Azure PowerShell を使用して Azure でのロールの割り当てを一覧表示する

Azure ロールベースのアクセス制御 (Azure RBAC) は、Azure のリソースに対するアクセスを管理するために使用する承認システムです。 ユーザー、グループ、サービスプリンシパル、またはマネージド ID がアクセスできるリソースを特定するには、ロールの割り当てを一覧表示します。 この記事では、Azure PowerShell を使用してロールの割り当てを一覧表示する方法を説明します。

注意

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、Azure PowerShell のインストールに関する記事を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

Note

組織で、Azure Lighthouse を使用するサービス プロバイダーに管理機能を外部委託している場合、そのサービス プロバイダーによって承認されているロールの割り当てはここに表示されません。 同様に、サービス プロバイダー テナント内のユーザーには、割り当てられているロールに関係なく、顧客のテナント内のユーザーに対するロールの割り当ては表示されません。

前提条件

現在のサブスクリプションにおけるロールの割り当ての一覧表示

現在のサブスクリプション内の (ルートと管理グループから継承されたロールの割り当てを含む) すべてのロールの割り当ての一覧を取得するもっと簡単な方法は、パラメーターの指定なしで Get-AzRoleAssignment を使用することです。

Get-AzRoleAssignment
PS C:\> Get-AzRoleAssignment

RoleAssignmentId   : /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleAssignments/11111111-1111-1111-1111-111111111111
Scope              : /subscriptions/00000000-0000-0000-0000-000000000000
DisplayName        : Alain
SignInName         : alain@example.com
RoleDefinitionName : Storage Blob Data Reader
RoleDefinitionId   : 2a2b9908-6ea1-4ae2-8e65-a410df84e7d1
ObjectId           : 44444444-4444-4444-4444-444444444444
ObjectType         : User
CanDelegate        : False

RoleAssignmentId   : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/pharma-sales/providers/Microsoft.Authorization/roleAssignments/33333333-3333-3333-3333-333333333333
Scope              : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/pharma-sales
DisplayName        : Marketing
SignInName         :
RoleDefinitionName : Contributor
RoleDefinitionId   : b24988ac-6180-42a0-ab88-20f7382dd24c
ObjectId           : 22222222-2222-2222-2222-222222222222
ObjectType         : Group
CanDelegate        : False

...

サブスクリプションのロールの割り当ての一覧表示

サブスクリプション スコープですべてのロールの割り当てを一覧表示するには、Get-AzRoleAssignment を使用します。 サブスクリプション ID を取得するには、Azure portal の [サブスクリプション] ブレードで、または Get-AzSubscription を使用して、その ID を見つけることができます。

Get-AzRoleAssignment -Scope /subscriptions/<subscription_id>
PS C:\> Get-AzRoleAssignment -Scope /subscriptions/00000000-0000-0000-0000-000000000000

ユーザーのロールの割り当ての表示

指定したユーザーに割り当てられているすべてのロールを一覧表示するには、Get-AzRoleAssignment を使用します。

Get-AzRoleAssignment -SignInName <email_or_userprincipalname>
PS C:\> Get-AzRoleAssignment -SignInName isabella@example.com | FL DisplayName, RoleDefinitionName, Scope

DisplayName        : Isabella Simonsen
RoleDefinitionName : BizTalk Contributor
Scope              : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/pharma-sales

To list all the roles that are assigned to a specified user and the roles that are assigned to the groups to which the user belongs, use Get-AzRoleAssignment.

Get-AzRoleAssignment -SignInName <email_or_userprincipalname> -ExpandPrincipalGroups
Get-AzRoleAssignment -SignInName isabella@example.com -ExpandPrincipalGroups | FL DisplayName, RoleDefinitionName, Scope

リソース グループに対するロールの割り当ての一覧表示

リソース グループのスコープですべてのロールの割り当てを一覧表示するには、Get-AzRoleAssignment を使用します。

Get-AzRoleAssignment -ResourceGroupName <resource_group_name>
PS C:\> Get-AzRoleAssignment -ResourceGroupName pharma-sales | FL DisplayName, RoleDefinitionName, Scope

DisplayName        : Alain Charon
RoleDefinitionName : Backup Operator
Scope              : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/pharma-sales

DisplayName        : Isabella Simonsen
RoleDefinitionName : BizTalk Contributor
Scope              : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/pharma-sales

DisplayName        : Alain Charon
RoleDefinitionName : Virtual Machine Contributor
Scope              : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/pharma-sales

管理グループに対するロールの割り当ての一覧表示

管理グループのスコープですべてのロールの割り当てを一覧表示するには、Get-AzRoleAssignment を使用します。 管理グループ ID を取得するには、Azure portal の [管理グループ] ブレードで確認するか、Get-AzManagementGroup を使用できます。

Get-AzRoleAssignment -Scope /providers/Microsoft.Management/managementGroups/<group_id>
PS C:\> Get-AzRoleAssignment -Scope /providers/Microsoft.Management/managementGroups/marketing-group

リソースに対するロールの割り当ての一覧表示

特定のリソースに対するロールの割り当てを一覧表示するには、Get-AzRoleAssignment-Scope パラメーターを使用します。 スコープは、リソースによって異なります。 スコープを取得するには、パラメーターを指定しないで Get-AzRoleAssignment を実行して、すべてのロールの割り当てを表示し、一覧表示するスコープを見つけます。

Get-AzRoleAssignment -Scope "/subscriptions/<subscription_id>/resourcegroups/<resource_group_name>/providers/<provider_name>/<resource_type>/<resource>

This following example shows how to list the role assignments for a storage account. Note that this command also lists role assignments at higher scopes, such as resource groups and subscriptions, that apply to this storage account.

PS C:\> Get-AzRoleAssignment -Scope "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/storage-test-rg/providers/Microsoft.Storage/storageAccounts/storagetest0122"

If you want to just list role assignments that are assigned directly on a resource, you can use the Where-Object command to filter the list.

PS C:\> Get-AzRoleAssignment | Where-Object {$_.Scope -eq "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/storage-test-rg/providers/Microsoft.Storage/storageAccounts/storagetest0122"}

従来のサービス管理者と共同管理者のロールの割り当てを一覧表示する

従来のサブスクリプション管理者と共同管理者のロールの割り当てを一覧表示するには、Get-AzRoleAssignment を使用します。

Get-AzRoleAssignment -IncludeClassicAdministrators

マネージド ID のロールの割り当ての一覧表示

次のステップを実行します。

  1. システム割り当てまたはユーザー割り当てのマネージド ID のオブジェクト ID を取得します。

    ユーザー割り当てのマネージド ID のオブジェクト ID を取得するには、Get-AzADServicePrincipal を使用します。

    Get-AzADServicePrincipal -DisplayNameBeginsWith "<name> or <vmname>"
    
  2. ロールの割り当てを一覧表示するには、Get-AzRoleAssignment を使用します。

    Get-AzRoleAssignment -ObjectId <objectid>
    

次のステップ