← Back to SOC feed Coverage →

PowershellCommand - uncommon commands on machine

kql MEDIUM Azure-Sentinel
DeviceEvents
huntingmicrosoftofficialpowershell
This rule was pulled from an open-source repository and enriched with AI. Validate in a test environment before deploying to production.
View original rule at Azure-Sentinel →
Retrieved: 2026-05-20T11:00:00Z · Confidence: medium

Hunt Hypothesis

Uncommon PowerShell cmdlets executed on a machine may indicate adversarial activity attempting to leverage unexpected or obfuscated commands for persistence or data exfiltration. SOC teams should proactively hunt for these commands in Azure Sentinel to identify potential compromise and mitigate lateral movement risks.

KQL Query

let DeviceId = "474908f457a1dc4c1fab568f808d5f77bf3bb951";
let timestamp = datetime(2018-06-09T02:23:26.6832917Z);
// Query for Powershell cmdlets
let powershellCommands =
    DeviceEvents
    | where ActionType == "PowerShellCommand"
    // Extract the powershell command name from the Command field in the AdditionalFields JSON column
    | project PowershellCommand=extractjson("$.Command", AdditionalFields, typeof(string)), InitiatingProcessCommandLine, InitiatingProcessParentFileName, Timestamp, DeviceId
    | where PowershellCommand !endswith ".ps1" and PowershellCommand !endswith ".exe";
// Filter Powershell cmdlets executed on relevant machine and time period
powershellCommands | where DeviceId == DeviceId and Timestamp between ((timestamp-5min) .. 10min)
// Filter out common powershell cmdlets
| join kind=leftanti (powershellCommands | summarize MachineCount=dcount(DeviceId) by PowershellCommand | where MachineCount > 20) on PowershellCommand

Analytic Rule Definition

id: 7d3acc08-312c-4139-85c9-f08299b79932
name: PowershellCommand - uncommon commands on machine
description: |
  Find which uncommon Powershell Cmdlets were executed on that machine in a certain time period.
  This covers all Powershell commands executed in the Powershell engine by any process.
requiredDataConnectors:
- connectorId: MicrosoftThreatProtection
  dataTypes:
  - DeviceEvents
query: |
  let DeviceId = "474908f457a1dc4c1fab568f808d5f77bf3bb951";
  let timestamp = datetime(2018-06-09T02:23:26.6832917Z);
  // Query for Powershell cmdlets
  let powershellCommands =
      DeviceEvents
      | where ActionType == "PowerShellCommand"
      // Extract the powershell command name from the Command field in the AdditionalFields JSON column
      | project PowershellCommand=extractjson("$.Command", AdditionalFields, typeof(string)), InitiatingProcessCommandLine, InitiatingProcessParentFileName, Timestamp, DeviceId
      | where PowershellCommand !endswith ".ps1" and PowershellCommand !endswith ".exe";
  // Filter Powershell cmdlets executed on relevant machine and time period
  powershellCommands | where DeviceId == DeviceId and Timestamp between ((timestamp-5min) .. 10min)
  // Filter out common powershell cmdlets
  | join kind=leftanti (powershellCommands | summarize MachineCount=dcount(DeviceId) by PowershellCommand | where MachineCount > 20) on PowershellCommand

Required Data Sources

Sentinel TableNotes
DeviceEventsEnsure this data connector is enabled

References

False Positive Guidance

Original source: https://github.com/Azure/Azure-Sentinel/blob/main/Hunting Queries/Microsoft 365 Defender/Execution/PowershellCommand - uncommon commands on machine.yaml