Hello VJ!
Welcome to Microsoft QnA! Hope you are doing well! 😊
To fetch all directory roles assigned to a user in Azure AD, including whether the roles are eligible or active, you can use the Azure AD PowerShell module or the Microsoft Graph API. It sounds like you're encountering a limitation with the current command, which may not be returning all roles due to pagination or query restrictions.
Here’s a PowerShell script using the AzureAD
module to fetch all the directory roles assigned to a user:
Install-Modu
$userId = "<UserObjectID>"
$roles = Get-AzureADUserAppRoleAssignment -ObjectId $userId
# Fetch details of the roles
$roles | ForEach-Object {
$role = Get-AzureADDirectoryRole | Where-Object { $_.ObjectId -eq $_.DirectoryRoleId }
$role
}
This script will retrieve all roles assigned to the specified user and display them. However, if you're still not getting all the roles, make sure to check if there is any paging or limitation in the API response.
If you're using the Microsoft Graph API, you can use this endpoint to get role assignments:
GET https://graph.microsoft.com/v1.0/users/{userId}/appRoleAssignments
To make sure you're getting all the roles, ensure you handle pagination if the response is too large.
Let me know if this works for you or if you need further assistance! 😊
✨ Please Upvote and Accept the Answer if it helps! ✨
Thanks & Regards,
Tasadduq Burney
(Microsoft MVP & MCT)
(Azure 15x)