Fixing the Failed To Acquire Token Error When Logging Into Azure from PowerShell

When I haven’t used Azure from PowerShell in some time, I’ll get an error “failed to acquire token” when using cmdlets such as Get-AzSubscription or Get-AzContext.

To add to the confusion, sometimes Connect-AzAccount appears to work and log me in, but I’ll still get the error.

Under the hood, the Azure cmdlets are caching some connection tokens. Fixing this issue is pretty simple, although not intuitive or easy to find the solution. All you have to do is issue the following cmdlet:

Clear-AzContext

This will remove old tokens from your system.

After issuing the clear command, just end your current PowerShell session, then login again using Connect-AzAccount and you should be good to go.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s