Skip to content

Commit 95e1a6e

Browse files
authored
Merge pull request #191050 from abhijeetsinha/patch-38
List transitiveRoleAssignments API
2 parents 27046c1 + f378002 commit 95e1a6e

File tree

1 file changed

+14
-81
lines changed

1 file changed

+14
-81
lines changed

articles/active-directory/roles/list-role-assignments-users.md

Lines changed: 14 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -46,111 +46,44 @@ Follow these steps to list Azure AD roles for a user using the Azure portal. You
4646

4747
Follow these steps to list Azure AD roles assigned to a user using PowerShell.
4848

49-
1. Install AzureADPreview and Microsoft.Graph module using [Install-module](/powershell/azure/active-directory/install-adv2).
49+
1. Install Microsoft.Graph module using [Install-module](/powershell/azure/active-directory/install-adv2).
5050

5151
```powershell
52-
Install-module -name AzureADPreview
5352
Install-module -name Microsoft.Graph
5453
```
55-
56-
2. Open a PowerShell window and use [Import-Module](/powershell/module/microsoft.powershell.core/import-module) to import the AzureADPreview module. For more information, see [Prerequisites to use PowerShell or Graph Explorer](prerequisites.md).
57-
58-
```powershell
59-
Import-Module -Name AzureADPreview -Force
60-
```
61-
62-
3. In a PowerShell window, use [Connect-AzureAD](/powershell/module/azuread/connect-azuread) to sign in to your tenant.
6354
64-
```powershell
65-
Connect-AzureAD
66-
```
67-
4. Use [Get-AzureADMSRoleAssignment](/powershell/module/azuread/get-azureadmsroleassignment) to get roles assigned directly to a user.
68-
69-
```powershell
70-
#Get the user
71-
$userId = (Get-AzureADUser -Filter "userPrincipalName eq '[email protected]'").ObjectId
72-
73-
#Get direct role assignments to the user
74-
$directRoles = (Get-AzureADMSRoleAssignment -Filter "principalId eq '$userId'").RoleDefinitionId
75-
```
76-
77-
5. To get transitive roles assigned to the user, use the following cmdlets.
78-
79-
a. Use [Get-AzureADMSGroup](/powershell/module/azuread/get-azureadmsgroup) to get the list of all role assignable groups.
55+
3. In a PowerShell window, Use [Connect-MgGraph](/graph/powershell/get-started) to sign into and use Microsoft Graph PowerShell cmdlets.
8056
8157
```powershell
82-
$roleAssignableGroups = (Get-AzureADMsGroup -All $true | Where-Object IsAssignableToRole -EQ 'True').Id
58+
Connect-MgGraph
8359
```
8460
85-
b. Use [Connect-MgGraph](/graph/powershell/get-started) to sign into and use Microsoft Graph PowerShell cmdlets.
86-
87-
```powershell
88-
Connect-MgGraph -Scopes "User.Read.All”
89-
```
90-
91-
c. Use [checkMemberObjects](/graph/api/user-checkmemberobjects) API to figure out which of the role assignable groups the user is member of.
92-
93-
```powershell
94-
$uri = "https://graph.microsoft.com/v1.0/directoryObjects/$userId/microsoft.graph.checkMemberObjects"
61+
4. Use the [List transitiveRoleAssignments](/graph/api/rbacapplication-list-transitiveroleassignments) API to get roles assigned directly and transitively to a user.
9562
96-
$userRoleAssignableGroups = (Invoke-MgGraphRequest -Method POST -Uri $uri -Body @{"ids"= $roleAssignableGroups}).value
97-
```
98-
99-
d. Use [Get-AzureADMSRoleAssignment](/powershell/module/azuread/get-azureadmsroleassignment) to loop through the groups and get the roles assigned to them.
100-
10163
```powershell
102-
$transitiveRoles=@()
103-
foreach($item in $userRoleAssignableGroups){
104-
$transitiveRoles += (Get-AzureADMSRoleAssignment -Filter "principalId eq '$item'").RoleDefinitionId
105-
}
64+
$response = $null
65+
$uri = "https://graph.microsoft.com/beta/roleManagement/directory/transitiveRoleAssignments?`$count=true&`$filter=principalId eq '6b937a9d-c731-465b-a844-2d5b5368c161'"
66+
$method = 'GET'
67+
$headers = @{'ConsistencyLevel' = 'eventual'}
68+
69+
$response = (Invoke-MgGraphRequest -Uri $uri -Headers $headers -Method $method -Body $null).value
10670
```
10771
108-
6. Combine both direct and transitive role assignments of the user.
109-
110-
```powershell
111-
$allRoles = $directRoles + $transitiveRoles
112-
```
113-
11472
## Microsoft Graph API
11573
11674
Follow these steps to list Azure AD roles assigned to a user using the Microsoft Graph API in [Graph Explorer](https://aka.ms/ge).
11775
11876
1. Sign in to the [Graph Explorer](https://aka.ms/ge).
11977
120-
1. Use the [List unifiedRoleAssignments](/graph/api/rbacapplication-list-roleassignments) API to get roles assigned directly to a user. Add following query to the URL and select **Run query**.
78+
1. Use the [List transitiveRoleAssignments](/graph/api/rbacapplication-list-transitiveroleassignments) API to get roles assigned directly and transitively to a user. Add following query to the URL.
12179
12280
```http
123-
GET https://graph.microsoft.com/v1.0/rolemanagement/directory/roleAssignments?$filter=principalId eq '55c07278-7109-4a46-ae60-4b644bc83a31'
81+
GET https://graph.microsoft.com/beta/rolemanagement/directory/transitiveRoleAssignments?$count=true&$filter=principalId eq '6b937a9d-c731-465b-a844-2d5b5368c161'
12482
```
12583

126-
3. To get transitive roles assigned to the user, follow these steps.
84+
3. Navigate to **Request headers** tab. Add `ConsistencyLevel` as key and `Eventual` as its value.
12785

128-
a. Use the [List groups](/graph/api/group-list) API to get the list of all role assignable groups.
129-
130-
```http
131-
GET https://graph.microsoft.com/v1.0/groups?$filter=isAssignableToRole eq true
132-
```
133-
134-
b. Pass this list to the [checkMemberObjects](/graph/api/user-checkmemberobjects) API to figure out which of the role assignable groups the user is member of.
135-
136-
```http
137-
POST https://graph.microsoft.com/v1.0/users/55c07278-7109-4a46-ae60-4b644bc83a31/checkMemberObjects
138-
{
139-
"ids": [
140-
"936aec09-47d5-4a77-a708-db2ff1dae6f2",
141-
"5425a4a0-8998-45ca-b42c-4e00920a6382",
142-
"ca9631ad-2d2a-4a7c-88b7-e542bd8a7e12",
143-
"ea3cee12-360e-411d-b0ba-2173181daa76",
144-
"c3c263bb-b796-48ee-b4d2-3fbc5be5f944"
145-
]
146-
}
147-
```
148-
149-
c. Use the [List unifiedRoleAssignments](/graph/api/rbacapplication-list-roleassignments) API to loop through the groups and get the roles assigned to them.
150-
151-
```http
152-
GET https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments?$filter=principalId eq '5425a4a0-8998-45ca-b42c-4e00920a6382'
153-
```
86+
5. Select **Run query**.
15487

15588
## Next steps
15689

0 commit comments

Comments
 (0)