Administrators assign app roles in Microsoft Entra ID to define user permissions and access levels within an application. This ensures that only authorized users can access specific features and data based on their roles. Microsoft Graph PowerShell's New-MgUserAppRoleAssignment command, an alternative to PowerShell's New-AzureADUserAppRoleAssignment command, can be used to assign app roles to users.
Before using the New-MgUserAppRoleAssignment cmdlet, ensure the Graph PowerShell module is installed. If not, install it using this script:
Install-Module Microsoft.Graph -Scope CurrentUser
The New-MgUserAppRoleAssignment cmdlet can be used in Graph PowerShell to assign app roles to users. Here's the syntax:
New-MgUserAppRoleAssignment
-UserId <String>
[-ResponseHeadersVariable <String>]
[-AdditionalProperties <Hashtable>]
[-AppRoleId <String>]
[-CreatedDateTime <DateTime>]
[-DeletedDateTime <DateTime>]
[-Id <String>]
[-PrincipalDisplayName <String>]
[-PrincipalId <String>]
[-PrincipalType <String>]
[-ResourceDisplayName <String>]
[-ResourceId <String>]
[-Headers <IDictionary>]
[-ProgressAction <ActionPreference>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Assign a user an application role
New-MgUserAppRoleAssignment -Userid '8a7c50d3-fcbd-4727-a889-8ab232dfea01' -PrincipalId '8a7c50d3-fcbd-4727-a889-8ab232dfea01' -ResourceId '0873169c-9595-4664-9d02-499b49846ff1' -AppRoleID '0004c632-673b-4105-9bb6-f3bbd2a927fe' |
Format-List Id, AppRoleId, CreationTime, PrincipalDisplayName,
PrincipalId, PrincipalType, ResourceDisplayName, ResourceId
The following table contains some parameters that can be used along with the New-MgUserAppRoleAssignment command to assign app roles to users:
| Parameters | Description |
|---|---|
| -AppRoleId | This parameter displays the identities for the app role that is assigned to the principal. |
| -CreatedDateTime | This parameter displays the date and time when the app role assignment was created. |
| -DeletedDateTime | This parameter displays the date and time when the object was deleted. |
| -PrincipalDisplayName | This parameter displays the user, group, or service principal that was granted the app role assignment. |
| -PrincipalId | This parameter displays the unique identifier of the user, security group, or service principal being granted the app role. |
ManageEngine ADManager Plus is an identity governance and administration solution with comprehensive Entra ID management and reporting capabilities. It eliminates the hassle of complex PowerShell scripts. Its intuitive, user-friendly interface allows you to streamline even the most complex administrative tasks in minutes.