Skip to content

Commit 13ae7c1

Browse files
committed
Updated document manage-roles-portal with MgGraph commands
1 parent dfaf190 commit 13ae7c1

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

articles/active-directory/roles/manage-roles-portal.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,65 +101,69 @@ Follow these steps to assign Azure AD roles using PowerShell.
101101
1. 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).
102102

103103
```powershell
104-
Import-Module -Name AzureADPreview -Force
104+
Import-Module -Name Microsoft.Graph.Identity.Governance -Force
105105
```
106106
107-
1. In a PowerShell window, use [Connect-AzureAD](/powershell/module/azuread/connect-azuread) to sign in to your tenant.
107+
1. In a PowerShell window, use [Connect-MgGraph](/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0&preserve-view=true) to sign in to your tenant.
108108
109109
```powershell
110-
Connect-AzureAD
110+
Connect-MgGraph -Scopes "RoleManagement.ReadWrite.Directory"
111111
```
112112
113-
1. Use [Get-AzureADUser](/powershell/module/azuread/get-azureaduser) to get the user you want to assign a role to.
113+
1. Use [Get-MgUser](/powershell/module/microsoft.graph.users/get-mguser?view=graph-powershell-1.0&preserve-view=true) to get the user you want to assign a role to.
114114
115115
```powershell
116-
$user = Get-AzureADUser -Filter "userPrincipalName eq 'user@contoso.com'"
116+
$user = Get-MgUser -Filter "userPrincipalName eq 'johndoe@contoso.com'"
117117
```
118118
119119
### Assign a role
120120
121-
1. Use [Get-AzureADMSRoleDefinition](/powershell/module/azuread/get-azureadmsroledefinition) to get the role you want to assign.
121+
1. Use [Get-MgRoleManagementDirectoryRoleDefinition](/powershell/module/microsoft.graph.identity.governance/get-mgrolemanagementdirectoryroledefinition?view=graph-powershell-1.0&preserve-view=true) to get the role you want to assign.
122122
123123
```powershell
124-
$roleDefinition = Get-AzureADMSRoleDefinition -Filter "displayName eq 'Billing Administrator'"
124+
$roledefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'Billing Administrator'"
125125
```
126126
127-
1. Use [New-AzureADMSRoleAssignment](/powershell/module/azuread/new-azureadmsroleassignment) to assign the role.
127+
1. Use [New-MgRoleManagementDirectoryRoleAssignment](/powershell/module/microsoft.graph.identity.governance/new-mgrolemanagementdirectoryroleassignment?view=graph-powershell-1.0&preserve-view=true) to assign the role.
128128
129129
```powershell
130-
$roleAssignment = New-AzureADMSRoleAssignment -DirectoryScopeId '/' -RoleDefinitionId $roleDefinition.Id -PrincipalId $user.objectId
130+
$roleassignment = New-MgRoleManagementDirectoryRoleAssignment -DirectoryScopeId '/' -RoleDefinitionId $roledefinition.Id -PrincipalId $user.Id
131131
```
132132
133133
### Assign a role as eligible using PIM
134134
135135
If PIM is enabled, you have additional capabilities, such as making a user eligible for a role assignment or defining the start and end time for a role assignment. These capabilities use a different set of PowerShell commands. For more information about using PowerShell and PIM, see [PowerShell for Azure AD roles in Privileged Identity Management](../privileged-identity-management/powershell-for-azure-ad-roles.md).
136136
137137
138-
1. Use [Get-AzureADMSRoleDefinition](/powershell/module/azuread/get-azureadmsroledefinition) to get the role you want to assign.
138+
1. Use [Get-MgRoleManagementDirectoryRoleDefinition](/powershell/module/microsoft.graph.identity.governance/get-mgrolemanagementdirectoryroledefinition?view=graph-powershell-1.0&preserve-view=true) to get the role you want to assign.
139139
140140
```powershell
141-
$roleDefinition = Get-AzureADMSRoleDefinition -Filter "displayName eq 'Billing Administrator'"
141+
$roledefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'Billing Administrator'"
142142
```
143143
144-
1. Use [Get-AzureADMSPrivilegedResource](/powershell/module/azuread/get-azureadmsprivilegedresource) to get the privileged resource. In this case, your tenant.
144+
1. Use the following command to create a hash table to store all the necessary attributes required to assign the role to the user. The Principal ID will be the user id to which you want to assign the role. In this example, the assignment will be valid only for **10 hours**.
145145
146146
```powershell
147-
$aadTenant = Get-AzureADMSPrivilegedResource -ProviderId aadRoles
148-
```
149-
150-
1. Use [New-Object](/powershell/module/microsoft.powershell.utility/new-object) to create a new `AzureADMSPrivilegedSchedule` object to define the start and end time of the role assignment.
151-
152-
```powershell
153-
$schedule = New-Object Microsoft.Open.MSGraph.Model.AzureADMSPrivilegedSchedule
154-
$schedule.Type = "Once"
155-
$schedule.StartDateTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
156-
$schedule.EndDateTime = "2021-07-25T20:00:00.000Z"
147+
$params = @{
148+
"PrincipalId" = "053a6a7e-4a75-48bc-8324-d70f50ec0d91"
149+
"RoleDefinitionId" = "b0f54661-2d74-4c50-afa3-1ec803f12efe"
150+
"Justification" = "Add eligible assignment"
151+
"DirectoryScopeId" = "/"
152+
"Action" = "AdminAssign"
153+
"ScheduleInfo" = @{
154+
"StartDateTime" = Get-Date
155+
"Expiration" = @{
156+
"Type" = "AfterDuration"
157+
"Duration" = "PT10H"
158+
}
159+
}
160+
}
157161
```
158162
159-
1. Use [Open-AzureADMSPrivilegedRoleAssignmentRequest](/powershell/module/azuread/open-azureadmsprivilegedroleassignmentrequest) to assign the role as eligible.
163+
1. Use [New-MgRoleManagementDirectoryRoleEligibilityScheduleRequest](/powershell/module/microsoft.graph.identity.governance/new-mgrolemanagementdirectoryroleeligibilityschedulerequest?view=graph-powershell-1.0&preserve-view=true) to assign the role as eligible. Once the role has been assigned, it will reflect on the Azure portal under **Privileged Identity Management -> Azure AD Roles -> Assignments -> Eligible Assignments** section.
160164
161165
```powershell
162-
$roleAssignmentEligible = Open-AzureADMSPrivilegedRoleAssignmentRequest -ProviderId 'aadRoles' -ResourceId $aadTenant.Id -RoleDefinitionId $roleDefinition.Id -SubjectId $user.objectId -Type 'AdminAdd' -AssignmentState 'Eligible' -schedule $schedule -reason "Review billing info"
166+
New-MgRoleManagementDirectoryRoleEligibilityScheduleRequest -BodyParameter $params | Format-List Id, Status, Action, AppScopeId, DirectoryScopeId, RoleDefinitionId, IsValidationOnly, Justification, PrincipalId, CompletedDateTime, CreatedDateTime
163167
```
164168
165169
## Microsoft Graph API

0 commit comments

Comments
 (0)