Image by mohammad takhsh on Unsplash
Intro
A quick post just to get me back into the routine, and to cover off an issue that I encountered recently, and how to resolve it.
The problem
I hadn’t done anything in Azure at home for a while and tonight I wanted to manage some VMs of mine from AZ Powershell.
First things first, connect my powershell session to my Azure account - easy right?
Connect-AzAccount -UseDeviceAuthentication
Click on the Device Login link:
Enter the onetime code in the browser:
Click on the account you wish to be signed in as:
Click to Continue
And then you see:
And you go back to your powershell session and see:
Notice anything wrong? There’s no SubscriptionName or TenantId shown.
So you think “Fine, I just need to tell it the Azure context for my subscription and tenant, so you issue the command:
Set-AzContext -SubscriptionID <SubscriptionID>
And you see an error like below:
The solution
So, the cached credentials for your Azure login are incorrect - in all likelihood, an expired access token.
So rather than work out why this happened, we just want to clear the cache.
And to do that?:
Clear-AzContext
This will give you a prompt like below:
If you enter Y and hit Enter it will clear the context.
Now, when you repeat the
Connect-AzAccount -UseDeviceAuthentication
command, you will see a far better response:
To wrap up, sometimes you just need to clear out your cache - and as ever, knowing which one, and where to look/how to do it, is half the battle!
I hope this helps if you find yourself in a similar position in future.
If you like what I do and appreciate the time and effort and expense that goes into my content you can always