使用管理群組大規模管理您的 Azure 訂用帳戶

如果您的組織有許多訂用帳戶,您可能需要有效管理那些訂用帳戶的存取權、原則與合規性的方法。 Azure 管理群組提供了訂用帳戶之上的範圍層級。 您要將訂用帳戶整理到稱為「管理群組」的容器中,並將治理條件套用至管理群組。 管理群組內的所有訂用帳戶都會自動繼承套用到管理群組的條件。

無論您具有何種類型的訂用帳戶,管理群組都可為您提供企業級的大規模管理功能。 若要深入了解管理群組,請參閱使用 Azure 管理群組來組織資源

注意

本文提供關於如何從裝置或服務刪除個人資料的步驟,並且可以用來支援遵循 GDPR 的義務。 如需 GDPR 的一般資訊,請參閱 Microsoft 信任中心的 GDPR 區段服務信任入口網站的 GDPR 區段

重要

Azure Resource Manager 使用者權杖和管理群組快取會持續 30 分鐘,之後系統便會強制加以重新整理。 在進行如移動管理群組或訂用帳戶之類的動作之後,其最多可能需要 30 分鐘才會顯示。 若要更快看見更新,您必須透過重新整理瀏覽器、登入並登出,或是要求新的權杖來更新您的權杖。

重要

AzManagementGroup 相關的 Az PowerShell Cmdlet 提及 -GroupId-GroupName 參數的別名,因此我們可以使用其中一個參數來提供管理群組識別碼以作為字串值。

變更管理群組的名稱

您可以使用入口網站、PowerShell 或 Azure CLI 來變更管理群組的名稱。

在入口網站中變更名稱

  1. 登入 Azure 入口網站

  2. 選取 [所有服務]>[管理群組]

  3. 選取您需要重新命名的管理群組。

  4. 選取 [詳細資料]

  5. 選取頁面頂端的 [重新命名群組] 選項。

    Screenshot of the action bar and the 'Rename Group' button on the management group page.

  6. 功能表開啟時,輸入您要顯示的新名稱。

    Screenshot of the Rename Group window and options to rename a management group.

  7. 選取 [儲存]。

在 PowerShell 中變更名稱

若要更新顯示名稱,請使用 Update-AzManagementGroup。 例如,若要將管理群組顯示名稱從 "Contoso IT" 變更為 "Contoso Group",您要執行下列命令:

Update-AzManagementGroup -GroupId 'ContosoIt' -DisplayName 'Contoso Group'

在 Azure CLI 中變更名稱

對於 Azure CLI,請使用 update 命令。

az account management-group update --name 'Contoso' --display-name 'Contoso Group'

刪除管理群組

若要刪除管理群組,必須符合下列需求:

  1. 管理群組下沒有任何子管理群組或訂用帳戶。 若要將訂用帳戶或管理群組移至另一個管理群組,請參閱在階層中移動管理群組和訂用帳戶

  2. 您必須具備管理群組上的寫入權限 (「擁有者」、「參與者」或「管理群組參與者」)。 若要查看您有哪些權限,請選取管理群組,然後選取 IAM。 若要深入瞭解 Azure 角色,請參閱 Azure 角色型存取控制 (Azure RBAC)

在入口網站中刪除

  1. 登入 Azure 入口網站

  2. 選取 [所有服務]>[管理群組]

  3. 選取您要刪除的管理群組。

  4. 選取 [詳細資料]

  5. 選取 [刪除]

    Screenshot of the Management group page with the 'Delete' button highlighted.

    提示

    如果無法使用圖示,將您的滑鼠選取器停留在圖示上會顯示原因。

  6. 視窗隨即開啟,確認您是否要刪除管理群組。

    Screenshot of the 'Delete group' confirmation dialog for deleting a management group.

  7. 選取 [是]

在 PowerShell 中刪除

使用 PowerShell 內的 Remove-AzManagementGroup 命令來將管理群組刪除。

Remove-AzManagementGroup -GroupId 'Contoso'

在 Azure CLI 中刪除

針對 Azure CLI,使用 az account management-group delete 命令。

az account management-group delete --name 'Contoso'

檢視管理群組

只您在管理群組中具有直接或繼承的 Azure 角色,您就可以檢視該管理群組。

在入口網站中檢視

  1. 登入 Azure 入口網站

  2. 選取 [所有服務]>[管理群組]

  3. 將會載入管理群組階層頁面。 此頁面是您可以探索所有可存取的管理群組和訂用帳戶的位置。 選取群組名稱即可前往階層中的較低層級。 瀏覽方式與檔案總管相同。

  4. 若要查看管理群組的詳細資訊,請選取管理群組標題旁的(詳細資料) 連結。 如果此連結無法使用,表示您沒有檢視該管理群組的權限。

    Screenshot of the Management groups page showing child management groups and subscriptions.

在 PowerShell 中檢視

您可以使用 Get-AzManagementGroup 命令來擷取所有群組。 請參閱 Az.Resources 模組以取得管理群組 GET PowerShell 命令的完整清單。

Get-AzManagementGroup

對於單一管理群組的資訊,請使用 -GroupId 參數

Get-AzManagementGroup -GroupId 'Contoso'

若要傳回特定的管理群組及其底下階層的所有層級,請使用 -Expand-Recurse 參數。

PS C:\> $response = Get-AzManagementGroup -GroupId TestGroupParent -Expand -Recurse
PS C:\> $response

Id                : /providers/Microsoft.Management/managementGroups/TestGroupParent
Type              : /providers/Microsoft.Management/managementGroups
Name              : TestGroupParent
TenantId          : 00000000-0000-0000-0000-000000000000
DisplayName       : TestGroupParent
UpdatedTime       : 2/1/2018 11:15:46 AM
UpdatedBy         : 00000000-0000-0000-0000-000000000000
ParentId          : /providers/Microsoft.Management/managementGroups/00000000-0000-0000-0000-000000000000
ParentName        : 00000000-0000-0000-0000-000000000000
ParentDisplayName : 00000000-0000-0000-0000-000000000000
Children          : {TestGroup1DisplayName, TestGroup2DisplayName}

PS C:\> $response.Children[0]

Type        : /managementGroup
Id          : /providers/Microsoft.Management/managementGroups/TestGroup1
Name        : TestGroup1
DisplayName : TestGroup1DisplayName
Children    : {TestRecurseChild}

PS C:\> $response.Children[0].Children[0]

Type        : /managementGroup
Id          : /providers/Microsoft.Management/managementGroups/TestRecurseChild
Name        : TestRecurseChild
DisplayName : TestRecurseChild
Children    :

在 Azure CLI 中檢視

您可以使用 list 命令來擷取所有群組。

az account management-group list

如需單一管理群組的資訊,請使用 show 命令

az account management-group show --name 'Contoso'

若要傳回特定的管理群組及其底下階層的所有層級,請使用 -Expand-Recurse 參數。

az account management-group show --name 'Contoso' -e -r

移動管理群組和訂用帳戶

建立管理群組的其中一個原因是要將訂用帳戶組合在一起。 只有管理群組和訂用帳戶才能設為另一個管理群組的子群組。 移至管理群組的訂用帳戶會繼承父管理群組中的所有使用者存取權和原則

將管理群組或訂用帳戶移為另一個管理群組的子系時,有三個規則必須評估為 true。

如果您要執行移動動作,則需要下列每一階層的權限:

  • 子訂用帳戶/管理群組
    • Microsoft.management/managementgroups/write
    • Microsoft.management/managementgroups/subscriptions/write (僅適用於訂用帳戶)
    • Microsoft.Authorization/roleAssignments/write
    • Microsoft.Authorization/roleAssignments/delete
    • Microsoft.Management/register/action
  • 目標父管理群組
    • Microsoft.management/managementgroups/write
  • 目前的父管理群組
    • Microsoft.management/managementgroups/write

例外狀況:如果目標或現有父管理群組是根管理群組,則不適用權限需求。 因為根管理群組是所有新管理群組和訂用帳戶的預設登陸點,所以您不需要其權限即可移動項目。

如果訂用帳戶上的擁有者角色繼承自目前的管理群組,則您的移動目標會受到限制。 您只能將訂用帳戶移至具有擁有者角色的另一個管理群組。 因為您會失去訂用帳戶的擁有權,所以無法將其移至您僅為參與者的管理群組。 如果直接將您指派給訂用帳戶的擁有者角色,您可以將其移至您是參與者的任何管理群組。

若要在 Azure 入口網站中查看您有哪些權限,請選取管理群組,然後選取 [IAM]。 若要深入瞭解 Azure 角色,請參閱 Azure 角色型存取控制 (Azure RBAC)

移動訂用帳戶

在入口網站中將現有的訂用帳戶新增到管理群組

  1. 登入 Azure 入口網站

  2. 選取 [所有服務]>[管理群組]

  3. 選取您計畫要作為父代的管理群組。

  4. 在頁面頂端,選取 [新增訂用帳戶]

  5. 在清單中選取具有正確識別碼的訂用帳戶。

    Screenshot of the 'Add subscription' options for selecting an existing subscription to add to a management group.

  6. 選取 [儲存]。

在入口網站中從管理群組移除訂用帳戶

  1. 登入 Azure 入口網站

  2. 選取 [所有服務]>[管理群組]

  3. 選取您正在規劃且目前為父代的管理群組。

  4. 針對清單中您需要移動的訂用帳戶資料列,選取資料列結尾省略符號。

    Screenshot of the alternative menu for a subscription to select the 'Move' option.

  5. 選取移動

  6. 在開啟的功能表上,選取父管理群組

    Screenshot of the 'Move' window and options for moving a subscription to a different management group.

  7. 選取 [儲存]。

在 PowerShell 中移動訂用帳戶

若要在 PowerShell 中移動訂用帳戶,您可以使用 New-AzManagementGroupSubscription 命令。

New-AzManagementGroupSubscription -GroupId 'Contoso' -SubscriptionId '12345678-1234-1234-1234-123456789012'

若要移除訂用帳戶與管理群組之間的連結,請使用 Remove-AzManagementGroupSubscription 命令。

Remove-AzManagementGroupSubscription -GroupId 'Contoso' -SubscriptionId '12345678-1234-1234-1234-123456789012'

在 Azure CLI 中移動訂用帳戶

若要在 CLI 移動訂用帳戶,您可以使用 add 命令。

az account management-group subscription add --name 'Contoso' --subscription '12345678-1234-1234-1234-123456789012'

若要將訂用帳戶從管理群組中移除,請使用 subscription remove 命令。

az account management-group subscription remove --name 'Contoso' --subscription '12345678-1234-1234-1234-123456789012'

在 ARM 範本中移動訂用帳戶

若要在 Azure Resource Manager 範本 (ARM 範本) 中移動訂用帳戶,請使用下列範本,並將其部署在租用戶層級

{
    "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "targetMgId": {
            "type": "string",
            "metadata": {
                "description": "Provide the ID of the management group that you want to move the subscription to."
            }
        },
        "subscriptionId": {
            "type": "string",
            "metadata": {
                "description": "Provide the ID of the existing subscription to move."
            }
        }
    },
    "resources": [
        {
            "scope": "/",
            "type": "Microsoft.Management/managementGroups/subscriptions",
            "apiVersion": "2020-05-01",
            "name": "[concat(parameters('targetMgId'), '/', parameters('subscriptionId'))]",
            "properties": {
            }
        }
    ],
    "outputs": {}
}

或以下 Bicep 檔案。

targetScope = 'managementGroup'

@description('Provide the ID of the management group that you want to move the subscription to.')
param targetMgId string

@description('Provide the ID of the existing subscription to move.')
param subscriptionId string

resource subToMG 'Microsoft.Management/managementGroups/subscriptions@2020-05-01' = {
  scope: tenant()
  name: '${targetMgId}/${subscriptionId}'
}

移動管理群組

在入口網站中移動管理群組

  1. 登入 Azure 入口網站

  2. 選取 [所有服務]>[管理群組]

  3. 選取您計畫要作為父代的管理群組。

  4. 在頁面頂端,選取 [新增管理群組]

  5. 在開啟的功能表中,選取是要新的管理群組還是使用現有管理群組。

    • 選取新項目即會建立新的管理群組。
    • 選取現有項目即會顯示您可移至此管理群組之所有管理群組的下拉式清單。

    Screenshot of the 'Add management group' options for creating a new management group.

  6. 選取 [儲存]。

在 PowerShell 中移動管理群組

在 PowerShell 中使用 Update-AzManagementGroup 命令,以移動不同群組下的管理群組。

$parentGroup = Get-AzManagementGroup -GroupId ContosoIT
Update-AzManagementGroup -GroupId 'Contoso' -ParentId $parentGroup.id

在 Azure CLI 中移動管理群組

您可以透過 Azure CLI 使用 update 命令來移動管理群組。

az account management-group update --name 'Contoso' --parent ContosoIT

使用活動記錄稽核管理群組

Azure 活動記錄中支援管理群組。 您可以在與其他 Azure 資源相同的中央位置,查詢在管理群組中發生的所有事件。 例如,您可以看到對特定的管理群組的所有角色指派或原則指派變更。

Screenshot of Activity Logs and operations related to the selected management group.

在 Azure 入口網站外部查詢管理群組時,管理群組的目標範圍像是 "/providers/Microsoft.Management/managementGroups/{yourMgID}"

參考來自其他資源提供者的管理群組

參考來自其他資源提供者之動作的管理群組時,請使用下列路徑作為範圍。 此路徑會在使用 PowerShell、Azure CLI 及 REST API 時使用。

/providers/Microsoft.Management/managementGroups/{yourMgID}

使用此路徑的一個範例,是在 PowerShell 中指派新的角色指派到管理群組:

New-AzRoleAssignment -Scope "/providers/Microsoft.Management/managementGroups/Contoso"

在管理群組中擷取原則定義時,也會使用相同的範圍路徑。

GET https://management.azure.com/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming?api-version=2019-09-01

下一步

若要深入了解管理群組,請參閱: