TheRocinante
TheRocinante

Reputation: 4201

Azure PowerShell automation "no default subscritpion has been designated"

I am getting the following error. I am in fact setting the default subscription name.

4/27/2015 10:28:28 AM, Error: Get-AzureVM : No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription. At test:9 char:9 + + CategoryInfo : CloseError: (:) [Get-AzureVM], ApplicationException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand

Here is my code:

workflow test
{
     # Initial set up
    $Cred = Get-AutomationPSCredential -Name "******"
    Add-AzureAccount -Credential $Cred
    Select-AzureSubscription -Default -SubscriptionName 'Beebunny'

    $vmName = "MyMachineName"
    Get-AzureVM -servicename $vmName

    Write-output "All done."
}

If I try Select-AzureSubscription -Default 'SubscriptionName' it throws an error saying the syntax is invalid.

Edit: I have also tried Select-AzureSubscription -SubscriptionName 'SubscriptionName' without the Default flag.

Funny thing is that if I run this in AzurePS directly from Windows, it runs just fine. I am about 95% sure this is an Azure bug but wanted to get a second opinion first.

Upvotes: 3

Views: 7083

Answers (2)

Óscar Andreu
Óscar Andreu

Reputation: 1700

I had the same problem and the solution was execute Add-AzureAccount, do the login process requested and once done all was working.

Upvotes: 2

Elizabeth Cooper
Elizabeth Cooper

Reputation: 215

What version of the Azure module do you have loaded? Are you using the default module provided by the Automation service? Also, have you imported any other modules to this subscription?

Try creating a clean runbook with the following code, replacing the credential and subscription with the proper names. Can you get the credential and authenticate successfully?

workflow Test-GetVM
{

    $Cred = Get-AutomationPSCredential -Name 'AdAzureCred'
    if(!$Cred) {
        Throw "Could not find an Automation Credential Asset named. Make sure you have created one in this Automation Account."
    }

    $Account = Add-AzureAccount -Credential $Cred
    if(!$Account) {
        Throw "Could not authenticate to Azure. Make sure the user name and password are correct."
    }

    Select-AzureSubscription -SubscriptionName "Visual Studio Ultimate with MSDN"
    Get-AzureVM
}

UPDATE: Do you have the Resource Manager module loaded to the subscription as well?

Upvotes: 2

Related Questions