4
votes

I'm trying to run some azure powershell commands as part of my Visual Studio Team Services build using Azure Resource Manager.

It gives me the following error:

No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription.

VSTS azure powershell error

The commands I'm trying to run:

$website = Get-AzureWebsite | where {$_.Name -eq 'my-website'}
Write-Output ("##vso[task.setvariable variable=DeployUrl;]$website.HostNames")

When I tried to run it locally, I had to call

Add-AzureAccount
Select-AzureRmSubscription -SubscriptionName "Visual Studio Premium with MSDN"

to get it working, but it is not possible in the VSTS build.

UPDATE:

I've configured it to use the azure classic mode instead of resource manager, at it works. I don't think that it is a feasible solution for production as azure classic mode is obsolete.

2
Get-AzureWebSite is the "classic" version of the cmdlet and so requires classic authn. Get-AzureRmWebApp, is the resource manager cmdlet. - bmoore-msft
Thanks! Could you please add an answer so that I can accept it? - Herr Kater
You can refer to Eddie's answer. - starian chen-MSFT
Yeah, I think Eddie covered it too - if something could be clarified lmk... - bmoore-msft

2 Answers

6
votes

Since you are using Azure Resource Manager, please check the things below:

  1. Make sure "Azure Resource Manager" service endpoint is added correctly.
  2. Use "Get-AzureRmWebApp" command instead of "Get-AzureWebsite" command just as bmoore mentioned.

I have tested it at my side, it works correctly.

My PowerShell script:

$website = Get-AzureRmWebApp | where {$_.Name -eq 'eddieapp0930'}
Write-Host $website.HostNames

Run from "Azure PowerShell Script" task: enter image description here

5
votes

Thank you for your question.

If you are using service manager mode(classic mode), the correct cmdlet is:
Add-AzureAccount
Get-AzureSubscription -SubscriptionName “name” | Select-AzureSubscription

If you are using Resource Manager, the correct cmdlet is:
Login-AzureRmAccount
Get-AzureRmSubscription –SubscriptionName "name" | Select-AzureRmSubscription

or just use -SubscriptionId instead of -SubscriptionName.

More information about ASM and ARM, please refer to the link below:
https://azure.microsoft.com/en-us/documentation/articles/resource-manager-deployment-model/

If you still have questions, welcome to post back here. Thanks.