skip to Main Content

we had an azure tenant.
we opened a new one, and passed our users to the new tenant and then added our users to the old tenants as guests.
Passing means that we deleted our users from the first tenant, then we migrated the domain to the new tenant and we created the users with the same properties in the new tenant.

since then every time we try to connect to azure using powershell with the commend Connect-azaccount -TenantId we get the following error:

Unable to acquire token for tenant '***' with error 'SharedTokenCacheCredential authentication unavailable. No account matching the specified username: *** tenantId: *** was found in the cache.'

does someone knows hoe to fix this?

thank you

we have tried every thing we found online.
we tries clear-azcontext, deleting the certificated from our machines, deleting powershell and reinstalling, etc…

2

Answers


  1. Unable to acquire token for tenant xxx with error SharedTokenCacheCredential authentication unavailable. No account matching the specified username: xxx tenantId: xxx was found in the cache

    The error usually occurs if the user is not present in the tenant you are trying to sign-in.

    To check the error in detail, you can try debugging like below:

    $DebugPreference = "Continue"
    Connect-AzAccount -TenantID XXXX
    

    enter image description here

    Based on the debug details, you can check which Tenant is the user being connected to or any user details.

    Try to connect with Subscription ID like below:

    Connect-AzAccount -Subscription SubscriptionID -TenantId TenantID
    

    enter image description here

    Check if the user is having MFA enabled and try connecting with Global Admin account. And it might be the scenario where the account might be still cached in the local machine, so try if it works in another machine.

    You can also make use of Device Authentication like below:

    Connect-AzAccount -Tenant TenantID -UseDeviceAuthentication
    

    Open the browser and enter the code:

    enter image description here

    Make sure to install the Az module like below:

    Initially clear the cache and try to install by setting execution policy

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
    Install-Module Az
    Import-Module Az
    Update-Module -Name Az
    

    enter image description here

    Check whether the user account in the Tenant has required permissions to the subscription.

    Try to select the Context in PowerShell:

    Get-AzContext -ListAvailable
    Select-AzContext -Name Name
    

    enter image description here

    Or you can set context to the SubscriptionID by including TenantID:

    Set-AzContext -Subscription $subscription -Tenant $tenantId | Out-null
    

    enter image description here

    If still the issue persists, it might be some environment problem while migrating the domain.

    Login or Signup to reply.
  2. For me the problem seemed to be related to using a "legacy" account (or whatever they’re called). Making and using a new account seemed to resolve the issue for me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search