Query Details
let query_frequency = 1h;
let query_period = 14d;
IdentityDirectoryEvents
| where TimeGenerated > ago(query_period)
| where ActionType == "PowerShell execution"
| extend
IsSuccess = tostring(AdditionalFields["IsSuccess"]),
Count = toint(AdditionalFields["Count"])
| summarize
Count = sum(Count),
arg_min(TimeGenerated, *)
by Protocol, AccountSid, DeviceName, IPAddress, DestinationDeviceName, IsSuccess
| where TimeGenerated > ago(query_frequency)
| project
TimeGenerated,
Timestamp,
Application,
ActionType,
Protocol,
DeviceName,
IPAddress,
AccountDisplayName,
AccountName,
AccountUpn,
AccountSid,
AccountDomain,
DestinationDeviceName,
IsSuccess,
Count,
AdditionalFields,
ReportId
This KQL (Kusto Query Language) query is designed to analyze identity directory events related to PowerShell executions over a specified period. Here's a simplified breakdown of what the query does:
Set Parameters:
query_frequency is set to 1 hour.query_period is set to 14 days.Filter Events:
IdentityDirectoryEvents table where the TimeGenerated is within the last 14 days.ActionType is "PowerShell execution".Extract and Convert Fields:
IsSuccess field from AdditionalFields and converts it to a string.Count field from AdditionalFields and converts it to an integer.Summarize Data:
Protocol, AccountSid, DeviceName, IPAddress, DestinationDeviceName, and IsSuccess.Count of events and finds the earliest TimeGenerated timestamp.Filter Recent Events:
TimeGenerated is within the last hour.Select and Display Fields:
In essence, this query helps identify and summarize recent PowerShell execution events, focusing on their success status and related details, within a specified timeframe.

Jose Sebastián Canós
Released: April 30, 2025
Tables
Keywords
Operators