Invoke-RestMethod : {“error”:{“code”:”InvalidAuthenticationTokenTenant”,”message”:”The access token is from the wrong issuer

A little bit shorter this time….

If you retrieved to many AccessTokens geholt and are trying to make a REST Call, this might happen:

Invoke-RestMethod : {“error”:{“code”:”InvalidAuthenticationTokenTenant”,”message”:”The access token is from the wrong issuer

You’ve got too many tokens, and PowerShell doesn’t know which one to use. Which we can see like this:

$context = Get-AzContext
$context.TokenCache

The easiest way to deal with this, is to simply clear the token cache:

(Get-AzContext).TokenCache.Clear() #Clear
(Get-AzContext).TokenCache #Verify

The next REST Call will prompt us for the credential.

Finally, when checking the token cache once again, we can see that there is no more confusion.