In today’s Azure Nugget I wanted to share with you some information about the Azure profile configuration file. Recently I experienced an issue when attempting to run Azure PowerShell cmdlets to deploy resources using Azure Resource Manager (ARM). Everything had been working fine and then all of the sudden I get the error below.
Get-AzureSubscription : Failed to refresh token. AADSTS90002: No service namespace named {‘GUID’} was found in the data store.
Looking a little closer I noticed a reference to a namespace that was a GUID for a tenant. Prior to the issue I had 2 active subscriptions and 1 expired. The expired subscription was the reference to this GUID. I took a look at my subscriptions within the Usage & Billing Portal and noticed only the 2 active were showing. So apparently the expired subscription had just purged from my Azure Account. If that was the case then why am I getting this error when trying to query my subscription info.
When the Microsoft Azure PowerShell module is installed there is this concept of an Azure PowerShell Configuration File. The file is located at C:\Users\{username}\AppData\Roaming\Windows Azure Powershell\AzureProfile.json. This is a JSON file containing sections of cached information for all subscriptions, accounts and environments that the account admin has configured on the system. After looking at this file in Visual Studio I could see that it was still referencing the expired subscription.
To resolve this issue I closed out all PowerShell consoles. Then I simply deleted the Windows Azure PowerShell folder containing the JSON file. After opening a new PowerShell console and running Add-AzureAccount, I could see the expired subscription tenant GUID was no longer present. Now I was able to query my subscriptions without error.
Hopefully this Azure Nugget has been helpful and will allow you to continue deploying resources with PowerShell and ARM. Until next time….