// question

Review Windows process and PowerShell activity for commands that enumerate PnP entities through WMI. Which PowerShell cmdlet was invoked to perform this hardware inventory?

Reference KQL answer and model-by-model comparison.

2cb4dbf2-2dca-4597-8678-4d39d207a3a5
question id
3/23
models correct
1
valid answer
13%
success rate
// reference answer

Human-validated correct answer for this question.

Get-WMIObject
// model comparison
ModelAnswerKQL queryStatusTriesTimeCost
gemini-2.5-flash-preview-04-17
no answer
no query generatedfail50.00s0.0315
gpt-35-turbo
no answer
no query generatedfail50.00s0.0110
gpt-4-turbo-2024-04-09
no answer
no query generatedfail50.00s0.2316
gpt-4.1
no answer
no query generatedfail50.00s0.0469
gpt-4.1-finetuned
no answer
no query generatedfail50.00s0.0459
gpt-4.1-mini
no answer
no query generatedfail50.00s0.0085
gpt-4.1-nano
no answer
no query generatedfail50.00s0.0019
gpt-4o
Invoke-AtomicTest T1057
DeviceProcessEvents
| where InitiatingProcessFileName == "powershell.exe"
| where ProcessCommandLine contains "Get-WmiObject" or ProcessCommandLine contains "Win32_PnPEntity"
| project InitiatingProcessCommandLine, InitiatingProcessFileName, DeviceName, ProcessCreationTime
fail17.62s0.0155
gpt-5-high
no answer
no query generatedfail50.00s0.1831
gpt-5-mini-high
Get-WMIObject
let targetRegex = @"(?i)\b(Get-?WmiObject|gwmi|Get-?CimInstance|gcim|Get-?PnpDevice|Get-?PnpDeviceProperty)\b";
union isfuzzy=true
    DeviceProcessEvents,
    DeviceEvents,
    DeviceFileEvents,
    DeviceImageLoadEvents,
    DeviceRegistryEvents
| extend CommandLine = coalesce(tostring(ProcessCommandLine), tostring(InitiatingProcessCommandLine), ""),
         ProcFile = tolower(coalesce(tostring(FileName), tostring(InitiatingProcessFileName), tostring(ProcessVersionInfoOriginalFileName), ""))
// Focus on PowerShell processes to reduce noise
| where ProcFile contains "powershell" or ProcFile contains "pwsh"
// Require presence of PnP/WMI/CIM keywords in the command line
| where CommandLine has_any ("Win32_PnPEntity","PnPDevice","PnPEntity","PnP","Get-WmiObject","gwmi","Get-CimInstance","gcim","Get-PnpDevice","Get-PnpDeviceProperty")
// Extract the invoked cmdlet if present
| extend MatchedCmdlet = extract(targetRegex, 1, CommandLine)
| extend MatchedCmdlet = case(isnotempty(MatchedCmdlet), MatchedCmdlet,
                              CommandLine has "Win32_PnPEntity", "Win32_PnPEntity",
                              "(unknown)")
// Aggregate to answer which cmdlet(s) performed the hardware inventory
| summarize Count = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated), ExampleCommand = any(CommandLine), ExampleDevice = any(DeviceName) by MatchedCmdlet
| order by LastSeen desc
pass251.30s0.0115
gpt-5-mini-low
Get-WmiObject
// Find PowerShell activity enumerating PnP entities via WMI
let wmiIndicators = dynamic(["Get-WmiObject","Get-CimInstance","Win32_PnPEntity","Win32_PnPDevice","PNPEntity","Win32_PnPEntity","Win32_PnPDevice","SELECT * FROM Win32_PnPEntity","Get-CimInstance -ClassName Win32_PnPEntity"]);
// Search DeviceProcessEvents for PowerShell processes and DeviceEvents for process creations invoking PowerShell
let psProcesses = (
    DeviceProcessEvents
    | where ProcessCommandLine has "powershell" or ProcessCommandLine has "pwsh" or ProcessCommandLine has "PowerShell" or ProcessCommandLine has "pwsh.exe"
    | where array_length(wmiIndicators) > 0
    | extend cmdline_lc = tolower(ProcessCommandLine)
    | where cmdline_lc has "get-wmiobject" or cmdline_lc has "get-ciminstance" or cmdline_lc has "win32_pnpentity" or cmdline_lc has "win32_pnpdevice" or cmdline_lc has "win32_pnp"
    | extend InvokedCmdlet = case(
        cmdline_lc has "get-wmiobject","Get-WmiObject",
        cmdline_lc has "get-ciminstance","Get-CimInstance",
        cmdline_lc has "gwmi","Get-WmiObject",
        cmdline_lc has "gcim","Get-CimInstance",
        "Other"
    )
    | project TimeGenerated, DeviceName, InitiatingProcessAccountName, ProcessId, ProcessCommandLine, InvokedCmdlet
);
let psFromDeviceEvents = (
    DeviceEvents
    | where ProcessCommandLine has "powershell" or ProcessCommandLine has "pwsh" or ProcessCommandLine has "PowerShell" or ProcessCommandLine has "pwsh.exe"
    | extend cmdline_lc = tolower(ProcessCommandLine)
    | where cmdline_lc has "get-wmiobject" or cmdline_lc has "get-ciminstance" or cmdline_lc has "win32_pnpentity" or cmdline_lc has "win32_pnpdevice" or cmdline_lc has "win32_pnp"
    | extend InvokedCmdlet = case(
        cmdline_lc has "get-wmiobject","Get-WmiObject",
        cmdline_lc has "get-ciminstance","Get-CimInstance",
        cmdline_lc has "gwmi","Get-WmiObject",
        cmdline_lc has "gcim","Get-CimInstance",
        "Other"
    )
    | project TimeGenerated, DeviceName, AccountName, ProcessId, ProcessCommandLine, InvokedCmdlet
);

psProcesses
| union psFromDeviceEvents
| summarize Count = count(), SampleCommandLines = make_set(ProcessCommandLine, 5) by InvokedCmdlet
| order by Count desc
| project InvokedCmdlet, Count, SampleCommandLines
pass114.12s0.0037
gpt-5-mini-medium
Get-WMIObject
let wmi_cmds_regex = @"(?i)\b(get-wmiobject|get-ciminstance|invoke-cimmethod|get-pnpdevice|get-pnpdeviceproperty|new-object\s+system.management.managementobjectsearcher|\[wmiclass\])\b";
let wmi_classes_regex = @"(?i)\b(Win32_PnPEntity|Win32_PnPDevice|Win32_USBControllerDevice|Win32_PnPAllocatedResource|Win32_PnPSignedDriver|Win32_USBHub)\b";

let proc_matches =
    DeviceProcessEvents
    | where (tolower(FileName) has "powershell" or tolower(InitiatingProcessFileName) has "powershell")
          or ProcessCommandLine matches regex wmi_cmds_regex
          or ProcessCommandLine matches regex wmi_classes_regex
    | extend MatchedCmdlet = extract(wmi_cmds_regex, 1, ProcessCommandLine)
    | extend MatchedClass = extract(wmi_classes_regex, 1, ProcessCommandLine)
    | extend Detected = tostring(coalesce(MatchedCmdlet, MatchedClass, "Unknown"))
    | project TimeGenerated, DeviceName, Account = InitiatingProcessAccountName, FileName, ProcessId, ProcessCommandLine, InitiatingProcessFileName, InitiatingProcessCommandLine, InitiatingProcessId, Detected;

let event_matches =
    DeviceEvents
    | where (tolower(FileName) has "powershell" or tolower(InitiatingProcessFileName) has "powershell")
          or ProcessCommandLine matches regex wmi_cmds_regex
          or ProcessCommandLine matches regex wmi_classes_regex
          or tostring(AdditionalFields) matches regex wmi_cmds_regex
    | extend MatchedCmdlet = extract(wmi_cmds_regex, 1, ProcessCommandLine)
    | extend MatchedClass = extract(wmi_classes_regex, 1, ProcessCommandLine)
    | extend MatchedInAdditional = extract(wmi_cmds_regex, 1, tostring(AdditionalFields))
    | extend Detected = tostring(coalesce(MatchedCmdlet, MatchedClass, MatchedInAdditional, "Unknown"))
    | project TimeGenerated, DeviceName, Account = InitiatingProcessAccountName, FileName, ProcessId, ProcessCommandLine, InitiatingProcessFileName, InitiatingProcessCommandLine, InitiatingProcessId, Detected;

proc_matches
| union event_matches
| where Detected != "Unknown"
| summarize Count = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated), Examples = make_set(ProcessCommandLine, 5) by Detected, DeviceName, Account
| order by LastSeen desc
| take 200
pass344.80s0.0130
gpt-5-nano-high
no answer
no query generatedfail50.00s0.0079
gpt-5-nano-medium
no answer
no query generatedfail50.00s0.0088
grok-3-beta
no answer
no query generatedfail50.00s0.0914
grok-3-mini-beta
no answer
no query generatedfail50.00s0.0081
o1-high
no answer
no query generatedfail50.00s0.9007
o1-low
no answer
no query generatedfail50.00s0.7446
o3-high
no answer
no query generatedfail50.00s0.0979
o3-mini-high
no answer
no query generatedfail50.00s0.0515
o3-mini-low
no answer
no query generatedfail50.00s0.0442
o4-mini-high
no answer
no query generatedfail50.00s0.0368
o4-mini-low
no answer
no query generatedfail50.00s0.0371