PowerShell Genie

Find processes outside Windows directories

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Query Win32_Process with Get-CimInstance to inspect executable paths outside C:\Windows, alongside process names and IDs.

The script

1PS> Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -and $_.ExecutablePath -notlike 'C:\Windows\*' } | Select-Object Name,ProcessId,ExecutablePath

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 Name ProcessId ExecutablePath
    2 ---- --------- --------------
    3 chrome.exe 9184 C:\Program Files\Google\Chrome\Application\chrome.exe
    4 Code.exe 6620 C:\Program Files\Microsoft VS Code\Code.exe
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -and $_.ExecutablePath -notlike 'C:\Windows\*' } | Select-Object Name,ProcessId,ExecutablePath
    1. Stage 1Get-CimInstancePositional values or no named parameters
    2. Stage 2Where-ObjectPositional values or no named parameters
    3. Stage 3Select-ObjectPositional values or no named parameters

      How it works

      Win32_Process is queried through Get-CimInstance, and the intent is to keep processes whose ExecutablePath is populated and does not sit under C:\Windows, reporting the image name, PID, and full path for each survivor.

      Adapting it

      Add a hash column by piping each ExecutablePath through Get-FileHash so the survivors can be checked against a reputation service in bulk rather than one filename at a time.

      Requirements

      Elevation, or ExecutablePath comes back blank for processes owned by other accounts.

      If the result is unexpected

      The process report misses executables or includes legitimate software outside Windows folders.

      ExecutablePath can be unavailable for protected processes, and location outside Windows is not evidence of malware.

      1. Inspect one missing process with the intended privileges and review its path, publisher and purpose.

      Validate the result

      Null paths are distinguished from excluded paths, and flagged processes have been individually reviewed.

      Keep the check reliable

      Keep exclusions explicit and label this report as an investigation starting point.

      Primary documentation

      Get-CimInstance reference

      Continue
      Genie guideFind processes outside Windows directories

      Query Win32_Process with Get-CimInstance to inspect executable paths outside C:\Windows, alongside process names and IDs.