Query Details
AuditLogs
| where TimeGenerated > ago(90d)
| where OperationName has_any ("Add member to group" ,"Remove member from group" , "Add owner to group" )
| extend Target = tostring(TargetResources[0].userPrincipalName)
| extend TargetId = TargetResources[0].id
| extend DisplayName = tostring(TargetResources[0].userPrincipalName)
| extend Initator =iff(isempty(parse_json(tostring(InitiatedBy.user)).userPrincipalName),parse_json(tostring(InitiatedBy.app)).displayName,(parse_json(tostring(InitiatedBy.user)).userPrincipalName))
| extend IPAddress= parse_json(tostring(InitiatedBy.user)).ipAddress
| extend GroupDisplayName = parse_json(tostring(parse_json(tostring(TargetResources[0].modifiedProperties))[1].newValue))
| where GroupDisplayName != "All Users"
| project TimeGenerated, Initator, Target,TargetId,DisplayName, IPAddress, GroupDisplayName
This KQL (Kusto Query Language) query is designed to analyze audit logs, specifically focusing on group membership changes within the last 90 days. Here's a simplified breakdown of what the query does:
Data Source: It starts by looking at the AuditLogs table.
Time Filter: It filters the logs to include only those generated in the last 90 days.
Operation Filter: It further narrows down the logs to those related to group membership changes, specifically when a member is added to a group, removed from a group, or when an owner is added to a group.
Data Extraction:
userPrincipalName of the target resource (the user affected by the operation) and stores it in Target and DisplayName.id of the target resource and stores it in TargetId.Initiator.IPAddress.GroupDisplayName.Exclusion: It excludes any operations related to the "All Users" group.
Output: Finally, it selects and displays the relevant columns: TimeGenerated, Initiator, Target, TargetId, DisplayName, IPAddress, and GroupDisplayName.
In summary, this query is used to track specific group membership changes in audit logs, excluding changes to the "All Users" group, and provides details about the operation, including who initiated it and the affected user.

Jay Kerai
Released: December 2, 2025
Tables
Keywords
Operators