Solved! Access token expiry error when deploying ARM Templates in Visual Studio

I was working on an ARM Template deployment using Visual Studio this morning, and out of the blue, I started getting the following error message.

ARM Templates

Here are the details of the error message:

12:28:42 - New-AzureRmResourceGroup : Operation returned an invalid status code ‘Unauthorized’

12:28:42 - At C:\Users\batman\Source\Repos\XXX-Firewall-Ingress\XXX-Firewall-Ingress-CP-MGMT\bin\Debug\staging\CIB

12:28:42 - C-Azure-Firewall-Ingress-CP-MGMT\Deploy-AzureResourceGroup.ps1:93 char:1

12:28:42 - + New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Resource ...

12:28:42 -     + CategoryInfo          : CloseError: (:) [New-AzureRmResourceGroup], CloudException

12:28:42 -     + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupCmdlet

12:28:43 - Test-AzureRmResourceGroupDeployment : The access token expiry UTC time ‘9/24/2018 1:12:39 AM’ is earlier than current UTC time ‘9/25/2018 4:28:43 PM’.

12:28:43 - At C:\Users\batman\Source\Repos\xxx-Firewall-Ingress\xxx-Firewall-Ingress-CP-MGMT\bin\Debug\staging\xxx-Firewall-Ingress-CP-MGMT\Deploy-AzureResourceGroup.ps1:96 char:47

12:28:43 - + ... tionOutput (Test-AzureRmResourceGroupDeployment -ResourceGroupName $R

12:28:43 -     + CategoryInfo          : CloseError: (:) [Test-AzureRmResourceGroupDeployment], CloudException

12:28:43 -     + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.TestAzureResourceGroupDeploymentCmdlet

The solution was simple: Just open a PowerShell session and connect again with Microsoft Azure subscription and select the right subscription. These following commands will help you in the process:
Connect-AzureRMAccount
(The above command will connect the PowerShell session with the Azure tenant.)
Get-AzureRMSubscription
(The above command will list all existent subscription available on this tenant.)

Select-AzureRMSubscription <SubscriptionName>
Disconnect-AzureRMAccount

(The above command will disconnect the session from PowerShell.)

Wouldn’t it be great if all errors could be solved this easily?

Featured image: Shutterstock

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top