Identity Directory Events Unusual Power Shell Execution
Query
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,
ReportIdExplanation
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_frequencyis set to 1 hour.query_periodis set to 14 days.
-
Filter Events:
- It retrieves events from the
IdentityDirectoryEventstable where theTimeGeneratedis within the last 14 days. - It specifically looks for events where the
ActionTypeis "PowerShell execution".
- It retrieves events from the
-
Extract and Convert Fields:
- It extracts the
IsSuccessfield fromAdditionalFieldsand converts it to a string. - It extracts the
Countfield fromAdditionalFieldsand converts it to an integer.
- It extracts the
-
Summarize Data:
- It groups the data by
Protocol,AccountSid,DeviceName,IPAddress,DestinationDeviceName, andIsSuccess. - For each group, it calculates the total
Countof events and finds the earliestTimeGeneratedtimestamp.
- It groups the data by
-
Filter Recent Events:
- It further filters the summarized data to include only those records where the
TimeGeneratedis within the last hour.
- It further filters the summarized data to include only those records where the
-
Select and Display Fields:
- Finally, it selects and displays a specific set of fields from the filtered data, including timestamps, account information, device details, and additional 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.
Details

Jose Sebastián Canós
Released: April 30, 2025
Tables
IdentityDirectoryEvents
Keywords
IdentityDirectoryEventsDeviceAccountIPAddressApplication
Operators
letagowhere==extendtostringtointsummarizesumarg_minbyproject