Unable to register ASDK: Get-AzToken : Unable to find type

PK_QTech 1 Reputation point


I have deployed ASDK version 1.2008.0.59. The installation was successful. I am now trying to register the ASDK using one of the accounts we have in our team. I am getting following error:

WARNING: Attempting to find a refresh token and an access token from the existing token cache data...
VERBOSE: 2021-02-16.06-24-32: Removing any existing PSSession...
Get-AzToken : Unable to find type [Microsoft.Azure.Commands.Common.Authentication.Authentication.Clients.AuthenticationClientFactory].
At C:\AzureStack-Tools-az\Registration\RegisterWithAzure.psm1:404 char:26

  • ... eshToken = (Get-AzToken -Context $AzureContext -FromCache -Verbose).G ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (Microsoft.Azure...onClientFactory:TypeName) [Get-AzToken], RuntimeException
  • FullyQualifiedErrorId : TypeNotFound,Get-AzToken

PS C:\Windows\system32>

We had registered ASDK using same account before but for some reason we had to re-deploy ASDK. We did that without de-registering. From what I have read online, we dont have to de-register in order re-deploy. Any idea what the error above is about?

I am using following script which is mentioned in ASDK docs:

Add the Azure cloud subscription environment name.

Supported environment names are AzureCloud, AzureChinaCloud, or AzureUSGovernment depending which Azure subscription you're using.

Connect-AzAccount -EnvironmentName "<environment name>"

Register the Azure Stack Hub resource provider in your Azure subscription

Register-AzResourceProvider -ProviderNamespace Microsoft.AzureStack

Import the registration module that was downloaded with the GitHub tools

Import-Module C:\AzureStack-Tools-az\Registration\RegisterWithAzure.psm1

If you have multiple subscriptions, run the following command to select the one you want to use:

Get-AzSubscription -SubscriptionID "<subscription ID>" | Select-AzSubscription

Register Azure Stack Hub

$AzureContext = Get-AzContext
$CloudAdminCred = Get-Credential -UserName AZURESTACK\CloudAdmin -Message "Enter the credentials to access the privileged endpoint."
$RegistrationName = "<unique-registration-name>"
Set-AzsRegistration -PrivilegedEndpointCredential $CloudAdminCred
-PrivilegedEndpoint AzS-ERCS01 -BillingModel Development
-RegistrationName $RegistrationName `

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
23,987 questions
{count} votes

2 answers

Sort by: Most helpful
  1. TravisCragg-MSFT 5,626 Reputation points Microsoft Employee

    Something tells me that there could be issues with your local PowerShell. Have you tried using the AzureRM module, as the Az module is still fairly new for the ASDK (its a different tab on the same page)?

    Also, if this is not working on the ASDK host computer, you can always do the offline registration.

    No comments

  2. James Orlando 1 Reputation point Microsoft Employee

    This can be resolved by reinstalling the modules. I ran into this exact issue on a machine that previously had AzureRM installed. I removed Azure RM (Uninstall-AzureRM from Az module), then followed this doc: https://learn.microsoft.com/en-us/azure-stack/operator/powershell-install-az-module?view=azs-2008#:~:text=%20Install%20PowerShell%20Az%20module%20for%20Azure%20Stack,PowerShell%20modules.%20Before%20installing%20the%20required...%20More%20

    Main thing being:
    Get-Module -Name Azure* -ListAvailable | Uninstall-Module -Force -Verbose -ErrorAction Continue
    Get-Module -Name Azs.* -ListAvailable | Uninstall-Module -Force -Verbose -ErrorAction Continue
    Get-Module -Name Az.* -ListAvailable | Uninstall-Module -Force -Verbose -ErrorAction Continue

    After closing that PS session and starting with a fresh AZ install I was good to go. Also, make sure your Azure Stack Tools are AZ as well. The folder should be AzureStack-Tools-Az and not AzureStack-Tools-Master.

    No comments