Query Details

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 desc

About 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:

  1. Time Frame: It looks at data from the last 30 days.
  2. Data Source: It uses the IdentityInfo table to gather information.
  3. Latest Record: For each user (identified by AccountObjectId), it selects the most recent record.
  4. Role Expansion: It expands the list of roles assigned to each user.
  5. Filter: It only considers users who have assigned roles.
  6. Summarization: For each user, it counts the total number of unique roles they have and creates a list of these roles.
  7. Additional Information: It adds the current date as the report date.
  8. 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 profile picture

Bert-Jan Pals

Released: October 20, 2024

Tables

IdentityInfo

Keywords

EntraIDRoleMembershipsUsers

Operators

letagowheresummarizearg_maxbymv-expandisnotemptydcounttostringmake_setextendnowsort

Actions

GitHub