Skip to content

Commit 72451cd

Browse files
authored
Merge pull request #197592 from rolyon/rolyon-aadroles-admin-units-assign-roles-powershell-update
[Azure AD roles] [Admin units] Assign role with admin unit scope powershell update
2 parents 80428d1 + d078c99 commit 72451cd

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

articles/active-directory/roles/admin-units-assign-roles.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.service: active-directory
99
ms.topic: how-to
1010
ms.subservice: roles
1111
ms.workload: identity
12-
ms.date: 03/22/2022
12+
ms.date: 05/09/2022
1313
ms.author: rolyon
1414
ms.reviewer: anandy
1515
ms.custom: oldportal;it-pro;
@@ -90,17 +90,16 @@ You can assign an Azure AD role with an administrative unit scope by using the A
9090
9191
### PowerShell
9292

93+
Use the [New-AzureADMSRoleAssignment](/powershell/module/azuread/new-azureadmsroleassignment) command and the `DirectoryScopeId` parameter to assign a role with administrative unit scope.
94+
9395
```powershell
94-
$adminUser = Get-AzureADUser -ObjectId "Use the user's UPN, who would be an admin on this unit"
95-
$role = Get-AzureADDirectoryRole | Where-Object -Property DisplayName -EQ -Value "User Administrator"
96-
$adminUnitObj = Get-AzureADMSAdministrativeUnit -Filter "displayname eq 'The display name of the unit'"
97-
$roleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo
98-
$roleMember.Id = $adminUser.ObjectId
99-
Add-AzureADMSScopedRoleMembership -Id $adminUnitObj.Id -RoleId $role.ObjectId -RoleMemberInfo $roleMember
96+
$user = Get-AzureADUser -Filter "userPrincipalName eq 'Example_UPN'"
97+
$roleDefinition = Get-AzureADMSRoleDefinition -Filter "displayName eq 'Example_role_name'"
98+
$adminUnit = Get-AzureADMSAdministrativeUnit -Filter "displayName eq 'Example_admin_unit_name'"
99+
$directoryScope = '/administrativeUnits/' + $adminUnit.Id
100+
$roleAssignment = New-AzureADMSRoleAssignment -DirectoryScopeId $directoryScope -RoleDefinitionId $roleDefinition.Id -PrincipalId $user.objectId
100101
```
101102

102-
You can change the highlighted section as required for the specific environment.
103-
104103
### Microsoft Graph API
105104

106105
Request
@@ -136,13 +135,13 @@ You can view all the role assignments created with an administrative unit scope
136135

137136
### PowerShell
138137

138+
Use the [Get-AzureADMSScopedRoleMembership](/powershell/module/azuread/get-azureadmsscopedrolemembership) command to list role assignments with administrative unit scope.
139+
139140
```powershell
140-
$adminUnitObj = Get-AzureADMSAdministrativeUnit -Filter "displayname eq 'The display name of the unit'"
141-
Get-AzureADMSScopedRoleMembership -Id $adminUnitObj.Id | fl *
141+
$adminUnit = Get-AzureADMSAdministrativeUnit -Filter "displayname eq 'Example_admin_unit_name'"
142+
Get-AzureADMSScopedRoleMembership -Id $adminUnit.Id | fl *
142143
```
143144

144-
You can change the highlighted section as required for your specific environment.
145-
146145
### Microsoft Graph API
147146

148147
Request

articles/active-directory/roles/custom-assign-powershell.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ Get-AzureADMSRoleAssignment -Filter "principalId eq '27c8ca78-ab1c-40ae-bd1b-eae
132132
Get-AzureADMSRoleAssignment -Filter "roleDefinitionId eq '355aed8a-864b-4e2b-b225-ea95482e7570'"
133133
```
134134

135-
### Delete a role assignment
135+
### Remove a role assignment
136136

137137
``` PowerShell
138-
# Delete role assignment
138+
# Remove role assignment
139139
Remove-AzureADMSRoleAssignment -Id 'qiho4WOb9UKKgng_LbPV7tvKaKRCD61PkJeKMh7Y458-1'
140140
```
141141

0 commit comments

Comments
 (0)