向 Azure 註冊 ASDKRegister the ASDK with Azure

您可以向 Azure 註冊 Azure Stack 開發套件 (ASDK) 安裝,以便從 Azure 下載市集項目,以及設定向 Microsoft 回報商務資料的功能。You can register your Azure Stack Development Kit (ASDK) installation with Azure to download marketplace items from Azure and to set up commerce data reporting back to Microsoft. 需要註冊才能支援完整的 Azure Stack Hub 功能,包括 marketplace 摘要整合。Registration is required to support full Azure Stack Hub functionality, including marketplace syndication. 需要註冊才能讓您測試重要的 Azure Stack Hub 功能,例如 marketplace 摘要整合和使用方式報告。Registration is required to enable you to test important Azure Stack Hub functionality like marketplace syndication and usage reporting. 註冊 Azure Stack Hub 之後,就會向 Azure commerce 回報使用量。After you register Azure Stack Hub, usage is reported to Azure commerce. 您可以在註冊時所使用的訂用帳戶下看到這項資訊。You can see it under the subscription you used for registration. 然而,ASDK 使用者將不需針對回報的任何使用方式支付費用。However, ASDK users aren't charged for any usage they report.

如果您尚未註冊 ASDK,您可能會看到 [需要啟用] 警告警示,提示您註冊 ASDK。If you don't register your ASDK, you might see an Activation Required warning alert that advises you to register your ASDK. 這是預期的行為。This behavior is expected.

PrerequisitesPrerequisites

在使用這些指示向 Azure 註冊 ASDK 之前,請確定您已安裝 Azure Stack Hub PowerShell 並下載 Azure Stack Hub 工具(如 部署後 設定文章所述)。Before using these instructions to register the ASDK with Azure, ensure that you've installed the Azure Stack Hub PowerShell and downloaded the Azure Stack Hub tools as described in the post-deployment configuration article.

在用來向 Azure 註冊 ASDK 的電腦上,PowerShell 語言模式也必須設定為 FullLanguageThe PowerShell language mode must also be set to FullLanguage on the computer used to register the ASDK with Azure. 若要確認目前的語言模式設定為完整,請開啟已提升權限的 PowerShell 視窗,並執行下列 PowerShell 命令:To verify that the current language mode is set to full, open an elevated PowerShell window and run the following PowerShell commands:

$ExecutionContext.SessionState.LanguageMode

確定輸出有傳回 FullLanguageEnsure the output returns FullLanguage. 如果傳回任何其他語言模式,則必須在另一部電腦上執行註冊,或是將語言模式設定為 FullLanguage,才能繼續。If any other language mode is returned, registration needs to be run on another computer or the language mode set to FullLanguage before continuing.

用於註冊的 Azure AD 帳戶必須具有 Azure 訂用帳戶的存取權,而且有權在與該訂用帳戶相關聯的目錄中建立身分識別應用程式和服務主體。The Azure AD account used for registration needs to have access to the Azure subscription and have permissions to create identity apps and service principals in the directory associated with that subscription. 建議您在 Azure 中註冊 Azure Stack Hub,方法是 建立要用於註冊的服務帳戶, 而不是使用全域管理員認證。We recommend you register Azure Stack Hub with Azure by creating a service account to use for registration rather than using global admin credentials.

註冊 ASDKRegister the ASDK

請遵循這些步驟來向 Azure 註冊 ASDK。Follow these steps to register the ASDK with Azure.

注意

這些步驟全都必須從可存取具有特殊權限之端點的電腦執行。All these steps must be run from a computer that has access to the privileged endpoint. 對於 ASDK 而言,這就是 ASDK 主機電腦。For the ASDK, that's the ASDK host computer.

  1. 開啟提升權限的 PowerShell 命令提示字元。Open an elevated PowerShell prompt.

  2. 執行下列 PowerShell Cmdlet,以向 Azure 註冊您的 ASDK 安裝。Run the following PowerShell cmdlets to register your ASDK installation with Azure. 登入 Azure 計費訂用帳戶識別碼與本機 ASDK 安裝。Sign in to both your Azure billing Subscription ID and the local ASDK installation. 如果您還沒有 Azure 計費訂用帳戶識別碼,您可以在此建立免費的 Azure 帳戶If you don't have an Azure billing subscription ID yet, you can create a free Azure account here. 註冊 Azure Stack Hub 不會對您的 Azure 訂用帳戶收取任何費用。Registering Azure Stack Hub incurs no cost on your Azure subscription.

    執行 Set-AzsRegistration Cmdlet 時,請設定註冊的唯一名稱。Set a unique name for the registration when you run the Set-AzsRegistration cmdlet. RegistrationName 參數的預設值是 AzureStackRegistrationThe RegistrationName parameter has a default value of AzureStackRegistration. 但是,如果您在多個 Azure Stack Hub 實例上使用相同的名稱,腳本將會失敗。However, if you use the same name on more than one instance of Azure Stack Hub, the script will fail.

    # Add the Azure cloud subscription environment name. 
    # Supported environment names are AzureCloud, AzureChinaCloud, or AzureUSGovernment depending which Azure subscription you're using.
    Add-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 `
    -UsageReportingEnabled:$true
    
  3. 當命令完成時,您會看到此訊息:您的環境現在已使用提供的參數註冊並啟動。When the script completes, you should see this message: Your environment is now registered and activated using the provided parameters.

您的環境現在已註冊

在中斷連線的環境中註冊Register in disconnected environments

如果您要在已中斷連線的環境中註冊 Azure Stack Hub (沒有網際網路連線) ,則需要從 Azure Stack Hub 環境中取得註冊權杖,然後在可連線到 Azure 的電腦上使用該權杖,為您的 ASDK 環境註冊並建立啟用資源。If you're registering Azure Stack Hub in a disconnected environment (with no internet connectivity), you need to get a registration token from the Azure Stack Hub environment and then use that token on a computer that can connect to Azure to register and create an activation resource for your ASDK environment.

重要

在使用這些指示來註冊 Azure Stack Hub 之前,請確定您已安裝適用于 Azure Stack Hub 的 PowerShell,並下載適用于 ASDK 主機電腦和電腦上的 部署後 設定文章中所述的 Azure Stack Hub 工具,以連線至 Azure 並進行註冊。Before using these instructions to register Azure Stack Hub, ensure that you've installed PowerShell for Azure Stack Hub and downloaded the Azure Stack Hub tools as described in the post-deployment configuration article on both the ASDK host computer and the computer with internet access used to connect to Azure and register.

從 Azure Stack Hub 環境中取得註冊權杖Get a registration token from the Azure Stack Hub environment

在 ASDK 主機電腦上,以系統管理員身分啟動 PowerShell,並流覽至您下載 Azure Stack Hub 工具時所建立的 AzureStack-Tools-az 目錄中的 註冊 資料夾。On the ASDK host computer, start PowerShell as an admin and navigate to the Registration folder in the AzureStack-Tools-az directory created when you downloaded the Azure Stack Hub tools. 使用下列 PowerShell 命令來匯入 RegisterWithAzure.psm1 模組,然後使用 Get-AzsRegistrationToken Cmdlet 來取得註冊權杖:Use the following PowerShell commands to import the RegisterWithAzure.psm1 module and then use the Get-AzsRegistrationToken cmdlet to get the registration token:

# Import the registration module that was downloaded with the GitHub tools
Import-Module C:\AzureStack-Tools-az\Registration\RegisterWithAzure.psm1

# Create registration token
$CloudAdminCred = Get-Credential -UserName AZURESTACK\CloudAdmin -Message "Enter the credentials to access the privileged endpoint."
# File path to save the token. This example saves the file as C:\RegistrationToken.txt.
$FilePathForRegistrationToken = "$env:SystemDrive\RegistrationToken.txt"
$RegistrationToken = Get-AzsRegistrationToken -PrivilegedEndpointCredential $CloudAdminCred `
-UsageReportingEnabled:$false `
-PrivilegedEndpoint AzS-ERCS01 `
-BillingModel Development `
-MarketplaceSyndicationEnabled:$false `
-TokenOutputFilePath $FilePathForRegistrationToken

儲存此註冊權杖,以在有網際網路連線的電腦上使用。Save this registration token for use on the internet-connected computer. 您可以從由 $FilePathForRegistrationToken 參數建立的檔案複製檔案或文字。You can copy the file or the text from the file created by the $FilePathForRegistrationToken parameter.

連線至 Azure 並註冊Connect to Azure and register

在與網際網路連線的電腦上,使用下列 PowerShell 命令來匯入 RegisterWithAzure.psm1 模組,然後用您剛才建立的註冊權杖和唯一的註冊名稱,使用 Register-AzsEnvironment Cmdlet 向 Azure 註冊:On the internet-connected computer, use the following PowerShell commands to import the RegisterWithAzure.psm1 module and then use the Register-AzsEnvironment cmdlet to register with Azure using the registration token you just created and a unique registration name:

# Add the Azure cloud subscription environment name. 
# Supported environment names are AzureCloud, AzureChinaCloud or AzureUSGovernment depending which Azure subscription you are using.
Add-AzAccount -EnvironmentName "<environment name>"

# 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 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

# Register with Azure
# This example uses the C:\RegistrationToken.txt file.
$registrationToken = Get-Content -Path "$env:SystemDrive\RegistrationToken.txt"
$RegistrationName = "<unique-registration-name>"
Register-AzsEnvironment -RegistrationToken $registrationToken `
-RegistrationName $RegistrationName

或者,您可以使用 Get-Content Cmdlet 來指向包含您註冊權杖的檔案:Alternatively, you can use the Get-Content cmdlet to point to a file that contains your registration token:

# Add the Azure cloud subscription environment name. 
# Supported environment names are AzureCloud, AzureChinaCloud or AzureUSGovernment depending which Azure subscription you are using.
Add-AzAccount -EnvironmentName "<environment name>"

# 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 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

# Register with Azure 
# This example uses the C:\RegistrationToken.txt file.
$registrationToken = Get-Content -Path "$env:SystemDrive\RegistrationToken.txt"
Register-AzsEnvironment -RegistrationToken $registrationToken `
-RegistrationName $RegistrationName

註冊完成時,您應該會看到類似以下的訊息: 您的 Azure Stack Hub 環境現在已向 Azure 註冊。When registration is complete, you should see a message similar to: Your Azure Stack Hub environment is now registered with Azure.

重要

關閉 PowerShell 視窗。Do not close the PowerShell window.

儲存註冊權杖和註冊資源名稱,供日後參考。Save the registration token and registration resource name for future reference.

從 Azure 註冊資源擷取啟用金鑰Retrieve an activation key from the Azure registration resource

仍使用網際網路連線的電腦,以及 相同的 PowerShell 主控台視窗,從您向 Azure 註冊時所建立的註冊資源中擷取啟用金鑰。Still using the internet-connected computer, and the same PowerShell console window, retrieve an activation key from the registration resource created when you registered with Azure.

若要取得啟用金鑰,請執行下列 PowerShell 命令。To get the activation key, run the following PowerShell commands. 使用您在上一個步驟中向 Azure 註冊時所提供的同一個唯一註冊名稱值:Use the same unique registration name value you provided when registering with Azure in the previous step:

$RegistrationResourceName = "<unique-registration-name>"
# File path to save the activation key. This example saves the file as C:\ActivationKey.txt.
$KeyOutputFilePath = "$env:SystemDrive\ActivationKey.txt"
$ActivationKey = Get-AzsActivationKey -RegistrationName $RegistrationResourceName `
-KeyOutputFilePath $KeyOutputFilePath

在 Azure Stack Hub 中建立啟用資源Create an activation resource in Azure Stack Hub

返回 Azure Stack Hub 環境,其中包含從 get-azsactivationkey 建立的啟用金鑰中的檔案或文字。Return to the Azure Stack Hub environment with the file or text from the activation key created from Get-AzsActivationKey. 執行下列 PowerShell 命令,以使用該啟用金鑰在 Azure Stack Hub 中建立啟用資源:Run the following PowerShell commands to create an activation resource in Azure Stack Hub using that activation key:

# Import the registration module that was downloaded with the GitHub tools
Import-Module C:\AzureStack-Tools-az\Registration\RegisterWithAzure.psm1

$CloudAdminCred = Get-Credential -UserName AZURESTACK\CloudAdmin -Message "Enter the credentials to access the privileged endpoint."
$ActivationKey = "<activation key>"
New-AzsActivationResource -PrivilegedEndpointCredential $CloudAdminCred `
-PrivilegedEndpoint AzS-ERCS01 `
-ActivationKey $ActivationKey

或者,您可以使用 Get-Content Cmdlet 來指向包含您註冊權杖的檔案:Alternatively, you can use the Get-Content cmdlet to point to a file that contains your registration token:

# Import the registration module that was downloaded with the GitHub tools
Import-Module C:\AzureStack-Tools-az\Registration\RegisterWithAzure.psm1

$CloudAdminCred = Get-Credential -UserName AZURESTACK\CloudAdmin -Message "Enter the credentials to access the privileged endpoint."
# This example uses the C:\ActivationKey.txt file.
$ActivationKey = Get-Content -Path "$env:SystemDrive\Activationkey.txt"
New-AzsActivationResource -PrivilegedEndpointCredential $CloudAdminCred `
-PrivilegedEndpoint AzS-ERCS01 `
-ActivationKey $ActivationKey

啟用完成時,您應會看到類似以下的訊息:您的環境已完成註冊和啟用程序。When activation is complete, you should see a message similar to: Your environment has finished the registration and activation process.

確認註冊已成功Verify the registration was successful

您可以使用 [區域管理] 圖格來確認 Azure Stack Hub 註冊是否已成功。You can use the Region management tile to verify that the Azure Stack Hub registration was successful. 此圖格位於系統管理員入口網站中的預設儀表板上。This tile is available on the default dashboard in the administrator portal.

  1. 登入 Azure Stack Hub 系統管理員入口網站 https://adminportal.local.azurestack.externalSign in to the Azure Stack Hub administrator portal https://adminportal.local.azurestack.external.

  2. 從儀表板中,選取 [Region management] (區域管理)。From the Dashboard, select Region management.

    Azure Stack Hub 管理員入口網站中的區域管理圖格Region management tile in Azure Stack Hub administrator portal

  3. 選取 [屬性] 。Select Properties. 此刀鋒視窗會顯示您環境的狀態和詳細資料。This blade shows the status and details of your environment. 狀態可以是 [已註冊] 或 [未註冊] 。The status can be Registered or Not registered. 如果是已註冊,則會一併顯示您用來註冊 Azure Stack Hub 的 Azure 訂用帳戶 ID,以及註冊資源群組和名稱。If registered, it also shows the Azure subscription ID that you used to register your Azure Stack Hub, along with the registration resource group and name.

移動註冊資源Move a registration resource

支援 在相同的訂用帳戶下的資源群組之間移動註冊資源。Moving a registration resource between resource groups under the same subscription is supported. 如需將資源移到新資源群組的詳細資訊,請參閱將資源移到新的資源群組或訂用帳戶For more info on moving resources to a new resource group, see Move resources to new resource group or subscription.

後續步驟Next steps