Role Report
Query
let TimeFrame = 30d;
IdentityInfo
| where Timestamp > ago(TimeFrame)
| summarize arg_max(TimeGenerated, *) by AccountObjectId
| mv-expand AssignedRoles
| where isnotempty(AssignedRoles)
| summarize TotalRoles = dcount(tostring(AssignedRoles)), MemberOf = make_set(tostring(AssignedRoles), 1000) by AccountObjectId, AccountDisplayName, AccountUPN
| extend ReportDate = now()
| sort by TotalRoles descAbout this query
Role Report
Query Information
Description
This query can be used to draw an report of the Entra ID role memberships for all users.
Defender XDR
Sentinel
let TimeFrame = 30d;
IdentityInfo
| where TimeGenerated > ago(TimeFrame)
| summarize arg_max(TimeGenerated, *) by AccountObjectId
| mv-expand AssignedRoles
| where isnotempty(AssignedRoles)
| summarize TotalRoles = dcount(tostring(AssignedRoles)), MemberOf = make_set(tostring(AssignedRoles), 1000) by AccountObjectId, AccountDisplayName, AccountUPN
| extend ReportDate = now()
| sort by TotalRoles desc
Explanation
This query is designed to generate a report on the role memberships of all users in Entra ID over the past 30 days. Here's a simple breakdown of what the query does:
- Time Frame: It looks at data from the last 30 days.
- Data Source: It uses the
IdentityInfotable to gather information. - Latest Record: For each user (identified by
AccountObjectId), it selects the most recent record. - Role Expansion: It expands the list of roles assigned to each user.
- Filter: It only considers users who have assigned roles.
- Summarization: For each user, it counts the total number of unique roles they have and creates a list of these roles.
- Additional Information: It adds the current date as the report date.
- Sorting: Finally, it sorts the users by the total number of roles they have, in descending order.
The query is essentially the same for both Defender XDR and Sentinel, focusing on providing a clear view of user role memberships within a specified time frame.
Details

Bert-Jan Pals
Released: October 20, 2024
Tables
IdentityInfo
Keywords
EntraIDRoleMembershipsUsers
Operators
letagowheresummarizearg_maxbymv-expandisnotemptydcounttostringmake_setextendnowsort