Azure 角色型存取控制 (Azure RBAC) 是您用來管理 Azure 資源存取權的授權系統。 若要判斷使用者、群組、服務主體或受控識別可以存取哪些資源,請列出其角色指派。 本文說明如何使用 Azure PowerShell 列出角色指派。
備註
建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 開始使用前,請參閱安裝 Azure PowerShell。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az。
備註
如果您的組織已將管理功能外包給使用 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。 若要取得訂用帳戶識別碼,您可以在 Azure 入口網站的 [訂用帳戶] 刀鋒視窗上找到它,也可以使用 Get-AzSubscription。
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
若要列出指派給指定使用者的所有角色,以及指派給使用者所屬群組的角色,請使用 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。 若要取得管理群組識別碼,您可以在 Azure 入口網站的 [ 管理群組 ] 刀鋒視窗中找到它,也可以使用 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>
下列範例示範如何列出儲存體帳戶的角色指派。 請注意,此命令也會列出適用於此儲存體帳戶的較高範圍 (例如資源群組和訂用帳戶) 的角色指派。
PS C:\> Get-AzRoleAssignment -Scope "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/storage-test-rg/providers/Microsoft.Storage/storageAccounts/storagetest0122"
如果您只想列出直接在資源上指派的角色指派,您可以使用 Where-Object 命令來篩選清單。
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
列出受控識別的角色指派
取得系統指派或使用者指派的受控識別的物件識別碼。
若要取得使用者指派受控識別的物件識別碼,您可以使用 Get-AzADServicePrincipal。
Get-AzADServicePrincipal -DisplayNameBeginsWith "<name> or <vmname>"若要列出角色指派,請使用 Get-AzRoleAssignment。
Get-AzRoleAssignment -ObjectId <objectid>