Encoded PowerShell grouped by parent process
Example entry. Shows which processes launch PowerShell with an encoded command, rarest first.
- Tables
- DeviceProcessEvents
- Tags
- endpoint, defender, hunting
- Updated
DeviceProcessEvents
| where Timestamp > ago(7d)
| where FileName in~ ("powershell.exe", "pwsh.exe")
| where ProcessCommandLine matches regex @"(?i)\s-e(nc(odedcommand)?)?\s"
| summarize Executions = count(),
Devices = dcount(DeviceId),
Sample = any(ProcessCommandLine)
by InitiatingProcessFileName
| order by Devices asc, Executions ascThis is a placeholder to show the format. Replace it with your own query, or delete the file.
What it does
Lists every parent process that started PowerShell with -e, -enc or -EncodedCommand in the last seven days. Parents seen on one or two devices sit at the top, which is where the interesting ones tend to be.
Tuning
Management agents and software deployment tools use encoded commands heavily. Exclude the ones you recognise by InitiatingProcessFileName once you have confirmed them.