Before you run
Data & scope
- Required tables
- Time window
- 24 hours
- Microsoft Entra ID connector with AuditLogs available for 24 hours and permission to inspect audit payloads.
- Any Microsoft Entra ID license supports audit ingestion; workspace query permissions and relevant administration evidence are required.
Documentation review by Codex (AI). No live-tenant execution or detection-performance claim. Validate schema, data coverage and expected results in your workspace.
// Hunting starter. Documentation checked 2026-11-13; not tenant-tested.
AuditLogs
| where TimeGenerated >= ago(1d) and TimeGenerated <= now()
| where Category =~ "RoleManagement" and Result =~ "success"
| extend AuditOperation = coalesce(ActivityDisplayName, OperationName)
| where AuditOperation in~ ("Add member to role", "Remove member from role",
"Add eligible member to role", "Remove eligible member from role",
"Add scoped member to role", "Remove scoped member from role",
"Add member to role completed (PIM activation)",
"Remove member from role completed (PIM deactivate)",
"Add member to role in PIM completed (permanent)",
"Add member to role in PIM completed (timebound)",
"Remove member from role in PIM completed (permanent)",
"Remove member from role in PIM completed (timebound)")
| extend ChangeClass = case(AuditOperation has "eligible", "Eligibility change",
AuditOperation has "scoped", "Scoped assignment change",
AuditOperation has "PIM", "Completed PIM change", "Direct membership change"),
ActorObjectId = coalesce(tostring(InitiatedBy.user.id),
tostring(InitiatedBy.app.servicePrincipalId)),
ActorName = coalesce(tostring(InitiatedBy.user.userPrincipalName),
tostring(InitiatedBy.app.displayName))
| project TimeGenerated, AADTenantId, AuditId = Id, AuditOperation,
ChangeClass, ActorObjectId, ActorName, TargetResources, AdditionalDetails, CorrelationId
| order by TimeGenerated desc
| take 200
Read-only query. Run in your own authorized workspace after checking prerequisites.
Use this hunt to review successful directory-role changes, including a selected set of completed Privileged Identity Management operations. The distinction between active membership, eligibility, scoped assignment and a completed activation matters: they grant or describe different kinds of authority.
Interpret the lifecycle explicitly
The query requires RoleManagement and success, then applies an exact operation list. Requested, approved and cancelled PIM lifecycle events are not selected simply because their text contains a role name. The list covers direct changes and several completed PIM paths; it is not every activity in the current audit catalog.
ChangeClass is an explanatory label for that list, not an authoritative privilege calculation. An eligible assignment does not mean that the user currently has an activated role. A removal can reflect scheduled expiry or normal deactivation. Confirm role, principal, scope, start/end times and assignment state against the underlying identity governance system.
The full TargetResources payload is retained rather than assuming the first target is always the role or the affected member. Microsoft defines target types and changed properties, but their layout depends on the operation. Target-resource contract. The initiating actor may be an administrator, an application or the PIM service rather than the person receiving authority.
Review the approval chain
Compare each change with its business owner, approval record and allowed scope. Investigate permanent privilege where time-bound access was intended. For removals, determine whether the operation restored the expected state or disrupted a required recovery path. Both additions and removals can be security-relevant.
Correlate subsequent privileged actions separately using stable identifiers and a tested timeline. A completed role event does not demonstrate that a later operation used that role, and current role inventory may differ from the event-time state.
Validate representative events
Test a direct assignment, eligible assignment, approved-but-not-completed request, completed activation and explicit completed PIM deactivation. Confirm that the request stays out while the completed cases appear. Compare the selected payloads with the administrative portal before creating automated entity mappings.
The query shows the latest 200 collected rows, not a deduplicated inventory of effective permissions. It does not cover Azure resource RBAC changes in AzureActivity or every group-based route to privilege. This documentation-checked hunt has not been tenant-tested. Verify collection and extend the explicit operation list only after validating new lifecycle names and semantics.
Verify the source
Microsoft references
Measure normal activity, validate known test cases, account for ingestion delays, choose a threshold and entity mapping, and assign an owner. Results require investigation.
Follow the detection learning path →