I was working with Windows Azure Automation using a MSDN account to create a run book that will run nightly to turn off all my running virtual machines. 

This is super easy and you area even provided a sample script that all you need to do is set your Active Directory (AD) User Name and your Subscription Name. 

Once I completed this and created an Automation Asset of Type Credential for my newly created AD User I was all set to go.  The AD User has been added as a co-administrator on the account to allow them access to the virtual machines. 

I set up the account like this:

With this configuration I received the following errors.

6/24/2015 8:27:46 PM, Error: Add-AzureAccount : user_realm_discovery_failed: User realm discovery failed: The remote server returned an error: (500)
Internal Server Error.
At Stop-AllAzureVM:35 char:35
+
    + CategoryInfo          : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
 
6/24/2015 8:27:47 PM, Error: Select-AzureSubscription : The subscription name Azure Pass doesn’t exist.
Parameter name: name
At Stop-AllAzureVM:39 char:39
+
    + CategoryInfo          : CloseError: (:) [Select-AzureSubscription], ArgumentException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand
 
6/24/2015 8:27:47 PM, Error: Get-AzureVM : No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to
set the default subscription.
At Stop-AllAzureVM:44 char:44
+
    + CategoryInfo          : CloseError: (:) [Get-AzureVM], ApplicationException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand

Lets loos closer at the User Name value setup in the Credential:

That’s right is has a space at the end of the name from doing a copy and paste of the user name.

If you run into this error you will want to check your user name setup under both the Asset Type of Credential and your user name entered in your script. 

Once I removed the space everything worked as expected..

Best of luck!