若要列出特定資源的角色指派,請使用 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"}