修復自動管理帳戶

重要

本文僅適用于已上線至舊版 Automanage 的電腦(API 版本 2020-06-30-preview)。 這些電腦的狀態將會是 [需要升級 ]。

您的 Azure Automanage 帳戶是自動化作業所依據的安全性內容或身分識別。 如果您最近已將包含自動管理帳戶的訂用帳戶移至新的租使用者,則必須重新設定帳戶。 若要重新設定,您必須重設身分識別類型,並為帳戶指派適當的角色。

步驟 1:重設 Automanage 帳戶身分識別類型

使用下列 Azure Resource Manager (ARM) 範本重設 Automanage 帳戶身分識別類型。 將檔案儲存為 armdeploy.json 或類似的名稱。 請注意您的 Automanage 帳戶名稱和位置,因為它們是 ARM 範本中的必要參數。

  1. 使用下列範本建立 Resource Manager 部署。 使用 identityType = None

    • 您可以使用 在 Azure CLI az deployment sub create 中建立部署。 如需詳細資訊,請參閱 az deployment sub
    • 您可以使用 模組在 PowerShell New-AzDeployment 中建立部署。 如需詳細資訊,請參閱 New-AzDeployment
  2. 使用 identityType = SystemAssigned 再次執行相同的 ARM 範本。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "accountName": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "identityType": {
            "type": "string",
            "allowedValues": [ "None", "SystemAssigned" ]
        }
    },
    "resources": [
        {
            "apiVersion": "2020-06-30-preview",
            "name": "[parameters('accountName')]",
            "location": "[parameters('location')]",
            "type": "Microsoft.Automanage/accounts",
            "identity": {
                "type": "[parameters('identityType')]"
            }
        }
    ]
}

步驟 2:為自動管理帳戶指派適當的角色

Automanage 帳戶需要訂用帳戶上的參與者和資源原則參與者角色,其中包含 Automanage 正在管理的 VM。 您可以使用 Azure 入口網站、ARM 範本或 Azure CLI 來指派這些角色。

如果您使用 ARM 範本或 Azure CLI,您將需要 Automanage 帳戶的主體識別碼(也稱為物件識別碼)。 (如果您使用 Azure 入口網站,則不需要識別碼。您可以使用下列方法來尋找此識別碼:

  • Azure CLI :使用 命令 az ad sp list --display-name <name of your Automanage Account>

  • Azure 入口網站:移至 Microsoft Entra ID ,並依名稱搜尋您的 Automanage 帳戶。 在 [企業應用程式] 下 ,選取 [自動管理帳戶名稱] 出現時。

Azure 入口網站

  1. 在 [訂用帳戶 ] 下 ,移至包含您自動受控 VM 的訂用帳戶。

  2. 選取 [存取控制 (IAM)]。

  3. 選取 [新增 > 角色指派 ] 以開啟 [ 新增角色指派 ] 頁面。

  4. 指派下列角色。 如需詳細步驟,請參閱使用 Azure 入口網站指派 Azure 角色

    設定
    角色 參與者
    存取權指派對象 使用者、群組或服務主體
    成員 <Automanage 帳戶的名稱>

    Screenshot showing Add role assignment page in Azure portal.

  5. 重複步驟 2 到 4,選取 [ 資源原則參與者 ] 角色。

ARM 範本

執行下列 ARM 範本。 您將需要 Automanage 帳戶的主體識別碼。 取得它的步驟位於本節的開頭。 出現提示時,請輸入識別碼。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "principalId": {
            "type": "string",
            "metadata": {
                "description": "The principal to assign the role to"
            }
        }
    },
    "variables": {
        "Contributor": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]",
        "Resource Policy Contributor": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', '36243c78-bf99-498c-9df9-86d9f8d28608')]"
    },
    "resources": [
        {
            "type": "Microsoft.Authorization/roleAssignments",
            "apiVersion": "2018-09-01-preview",
            "name": "[guid(uniqueString(variables('Contributor')))]",
            "properties": {
                "roleDefinitionId": "[variables('Contributor')]",
                "principalId": "[parameters('principalId')]"
            }
        },
        {
            "type": "Microsoft.Authorization/roleAssignments",
            "apiVersion": "2018-09-01-preview",
            "name": "[guid(uniqueString(variables('Resource Policy Contributor')))]",
            "properties": {
                "roleDefinitionId": "[variables('Resource Policy Contributor')]",
                "principalId": "[parameters('principalId')]"
            }
        }
    ]
}

Azure CLI

執行以下命令:

az role assignment create --assignee-object-id <your Automanage Account Object ID> --role "Contributor" --scope /subscriptions/<your subscription ID>

az role assignment create --assignee-object-id <your Automanage Account Object ID> --role "Resource Policy Contributor" --scope /subscriptions/<your subscription ID>

下一步

深入瞭解 Azure Automanage