Investigation · Execution
What did PowerShell run on this host?
Recover PowerShell activity: the de-obfuscated code from script block logging, the engine version used, and the commands tied to the process that ran them.
When you would ask thisYou suspect PowerShell was used for download, execution or credential theft and need the actual code, not just that powershell.exe launched.
Steps
- 1
Pull script block logging first
Event 4104 in the PowerShell Operational log records the code PowerShell compiled, after de-obfuscation. Read ScriptBlockText for the content and ScriptBlockId to group a script. Even without policy enabled, PowerShell 5 logs blocks it considers suspicious at Warning level, so the absence of a logging GPO does not mean no 4104 events exist. Large scripts are split across several 4104 events; reassemble them in order using MessageNumber and MessageTotal under the same ScriptBlockId.
Find suspicious script blocks (live host)Get-WinEvent -LogName 'Microsoft-Windows-PowerShell/Operational' ` -FilterXPath "*[System[EventID=4104]]" | Where-Object { $_.Message -match 'FromBase64String|-enc |IEX|Invoke-Expression|DownloadString' } | Select-Object TimeCreated, Id, Message - 2
Add module logging for pipeline detail
Event 4103 records pipeline execution with the command and its bound parameters, plus the host application. It fills gaps where 4104 only shows the defined script block and not how it was invoked. It is high volume and only present where Module Logging is configured, so treat it as a bonus source rather than something you can rely on. Correlate 4103 and 4104 by time and by the host process to reconstruct both the code and the invocation.
- 3
Check the engine version for a downgrade
The classic Windows PowerShell log records engine lifecycle. Event 400 is written when any PowerShell host starts and carries EngineVersion, HostName and HostApplication; 403 marks the engine stopping and 600 provider lifecycle. An EngineVersion of 2.0 is a red flag: PowerShell 2.0 has no script block logging, so attackers force a downgrade to blind the 4104 source. Seeing 2.0 here with no matching 4104 activity is the downgrade, not missing logs.
- 4
Use classic pipeline logging where it exists
Event 800 in the Windows PowerShell log records pipeline execution details, including HostApplication and the command line, on systems where the classic log captured it. It predates the Operational log and sometimes survives when the Operational log has rolled. Use it to confirm what a given host process ran, and to extend coverage on older systems that never had script block logging configured.
- 5
Tie the activity to a process and parent
Resolve which process produced the script blocks. Process creation 4688 (and Sysmon 1, which adds hashes and the parent command line) shows powershell.exe or pwsh.exe with its full command line, exposing -EncodedCommand, -WindowStyle Hidden and the parent that spawned it. A PowerShell child of winword.exe, wscript.exe or a service points to initial execution. Match the process start time and command line to the 4104 timestamps to attribute the code to a specific run.
- 6
Spot remoting and console start-up
Operational events 40961 and 40962 mark the PowerShell console starting up and becoming ready for input; a burst of these without an interactive user suggests automated or remote invocation. For PowerShell Remoting specifically, pair them with the WinRM log: event 6 on the source names the destination of an outbound session and 91 on the destination records the inbound shell being created. Together they show whether the PowerShell ran locally or arrived over WinRM.
Where it goes wrong
- A forced downgrade to PowerShell 2.0 (visible as EngineVersion 2.0 in event 400) disables script block logging entirely, so a quiet 4104 source is itself a finding.
- 4104 splits large scripts across multiple events; reassemble by ScriptBlockId using MessageNumber and MessageTotal or you will analyze a fragment.
- PowerShell 5 auto-logs suspicious blocks at Warning level even with no policy, so do not assume missing GPO means no evidence; conversely, a clean environment will still miss benign code.
- PowerShell 7 (pwsh.exe) logs to Microsoft-Windows-PowerShell-Core/Operational, a different channel, so pulling only the 5.x Operational log misses it.
- The PowerShell Operational log defaults to about 15 MB and script block logging is verbose, so it rolls quickly on an active host.
- Module logging (4103) is very high volume and often truncates or is simply not enabled; absence is not evidence.
Beyond event logs
PSReadLine console history
%APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
Per-user plaintext history of commands typed interactively. It persists across reboots and is not an event log, so it often survives when PowerShell logging was off. It does not capture non-interactive or -EncodedCommand execution.
PowerShell transcripts
The transcript output directory set by policy (often a share or C:\Transcripts)
If transcription was enabled, these text files record full input and output of sessions, which can be richer than 4104. Check whether policy pointed them at a writable share the attacker could tamper with.
Prefetch and Amcache
C:\Windows\Prefetch\POWERSHELL.EXE-*.pf and C:\Windows\AppCompat\Programs\Amcache.hve
Confirm powershell.exe or pwsh.exe executed and when, independent of any PowerShell logging, and give the binary's SHA-1 from Amcache.