Add-AzureAccount : Index was out of range. Must be a non-negative and less than the size of the collection Add-AzureAccount : Index was out of range. Must be a non-negative and less than the size of the collection powershell powershell

Add-AzureAccount : Index was out of range. Must be a non-negative and less than the size of the collection


I know exactly what caused this error for me, and how I worked around it (I thought I was the only one who had seen this :))

What had happened is that I had accidentally added a bogus/empty subscription to my account. And this empty subscription had been set to my "default" subscription.

Run "get-azuresubscription -default" to see what your default subscription is. You can then "remove" any junk subscriptions using "remove-azuresubscription" command.

You can then of course set a new azure subscription for your "default" using PS.

I actually reported this to the Azure PowerShell team now to get a better error message during this scenario.Hopefully this solved your problem, it's possible other errors manifest the same error message.


If you do a fiddler trace, you should see that right after the login call (where PowerShell passes in your username/password, there should be 1 or multiple calls to GET /subscriptions.

Check the response to see whether there is anything suspicious there. Like, any of them return an empty body, empty array, subscription with id, name, etc..


I had a similar problem recently. The "fix" was for me was to delete the files at C:\Users[username]AppData\Roaming\Windows Azure Powershell (esp. the WindowsAzureProfile.xml file). The next time I ran Add-AzureAccount, the necessary files were created and all was well.