共用方式為


修復 Automanage 帳戶

重要

本文僅適用於在舊版 Automanage (API 2020-06-30-preview) 上線的機器。 這些機器的狀態將會是需要升級

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

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

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

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

    • 您可以使用 az deployment sub create,在 Azure CLI 中建立部署。 如需詳細資訊,請參閱 az deployment sub
    • 您可以使用 New-AzDeployment 模組,在 PowerShell 中建立部署。 如需詳細資訊,請參閱 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 帳戶需要訂用帳戶上的參與者和資源原則參與者角色,其中包含 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,並依名稱搜尋 Automanage 帳戶。 在 [企業應用程式] 底下,選取出現的 Automanage 帳戶名稱。

Azure 入口網站

  1. 在 [訂用帳戶] 下,移至內含自動管理 VM 的訂用帳戶。

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

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

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

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

    此螢幕擷取畫面顯示 Azure 入口網站中的 [新增角色指派] 頁面。

  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