Query Details
AuditLogs | where TimeGenerated > ago(90d) | where OperationName == "Delete user" | where Result == "success" | extend TargetId = tostring(TargetResources[0].id) | extend Target = substring(tostring(TargetResources[0].userPrincipalName),32)//replace_string(tostring(TargetResources[0].userPrincipalName),TargetId,'') | extend DisplayName = tostring(TargetResources[0].userPrincipalName) | extend Initiator =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
This KQL (Kusto Query Language) query is designed to analyze audit logs and extract specific information about successful user deletion operations 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 filters the logs to include only entries where the operation performed was "Delete user."
Result Filter: It ensures that only successful deletion operations are considered by checking if the result is "success."
Extract Target Information:
TargetId from the first resource in the TargetResources array.Target by taking a substring of the userPrincipalName from the first resource, starting from the 32nd character.DisplayName from the userPrincipalName of the first resource.Extract Initiator Information:
Initiator of the deletion operation. If the userPrincipalName is empty, it uses the displayName from the app information; otherwise, it uses the userPrincipalName.IPAddress of the initiator from the user information.Overall, this query is used to identify and summarize details about successful user deletions, including who was deleted, who initiated the deletion, and from which IP address the operation was performed.

Jay Kerai
Released: December 2, 2025
Tables
Keywords
Operators