Partager via


Add-AzureAccount issue: Your Azure credentials have not been set up or have expired

For some reason, I started experiencing this issue. Tried clearing the local cache, temp folders or cookies etc but none helped. So grabbed fiddler log to see what is going wrong. Noticed it was having the very old session token (3-4 months older) getting served for some reason and no clue where it lies also. Checked few command lets to clear this out within PS and noted Clear-AzureProfile flushed the older tokens which resolved this issue.

PS C:\WINDOWS\system32> Add-AzureAccount

Id Type Subscriptions Tenants

-- ---- ------------- -------

xxxx@microsoft.com User xx-c5bc-xx-a7e0-xx{xxx-86f1-41af-91ab-xxxx}

PS C:\WINDOWS\system32> Get-AzureRoleSize

Get-AzureRoleSize : Your Azure credentials have not been set up or have expired, please run Add-AzureAccount to set up your Azure credentials.

At line:1 char:1

+ Get-AzureRoleSize

+ ~~~~~~~~~~~~~~~~~

+ CategoryInfo : CloseError: (:) [Get-AzureRoleSize], ArgumentException

+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.HostedServices.AzureRoleSizeCommand

 

Solution:-

Run the Clear-AzureProfle Commandlet and then try Add-AzureAccount to get the valid bearer token to continue.

PS C:\WINDOWS\system32> Clear-AzureProfile –Force

Let me know if you see this issue and root cause for this.

Happy scripting…

Comments

  • Anonymous
    March 13, 2017
    You are my saviour - I was going absolutely mad with this exact same problem. Thank you so much.
  • Anonymous
    June 05, 2017
    Helped a lot! Thanks for sharing.
  • Anonymous
    June 14, 2017
    Thank you so much, perfect solution. I think its because I've used Azure a few times on same machine with different subscriptions so it must have remembered something from previous one. Thank you
  • Anonymous
    July 12, 2017
    Wow... Thank you very much :)
  • Anonymous
    July 21, 2017
    This is not working for me when I attempt to get access to an Azure SQL database.
  • Anonymous
    December 11, 2017
    Bulls eye !! Works for me as well. Thanks so much.
  • Anonymous
    January 29, 2018
    The root issue is likely that the token cache wasn't refreshed during your login, there appear to be some circumstances in which expired refresh tokens are not updated when new refresh tokens are returned during login. Clear-AzureProfile automatically clears the entire token cache, so that the new refresh tokens returned by login are automatically renewed.To see if this is the issue, after importing the module, you can run [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.TokenCache.ReadItems() | select -Property DisplayableId, Resource, ExpiresOn
    • Anonymous
      January 29, 2018
      Thanks Mark. We will check and update here.
  • Anonymous
    August 23, 2018
    This saved us. We're using an Azure Active Directory account to Login; the account's password expired on Tuesday. We found that we had to run Clear-AzureProfile -Force in order for AzureRM cmdlets (such as Invoke-AzureRmResourceAction) to work even following Add-AzureRmAccount and Set-AzureRmContext.