When an intruder has used PowerShell on a Windows estate, the evidence of what they ran is scattered across several event logs, per-user history files and transcript folders, and each source captures something different. Responders who know which artefact holds what can rebuild an attacker's commands, decoded payloads and timeline offline, even after logs have been partly cleared. Responders who rely on one source miss most of it. This guide is for incident responders and forensic analysts working on a collected image or triage package. It covers each PowerShell artefact in depth, how to collect it without contaminating it, how to reassemble split script blocks and correlate sources into a timeline, and how to tell when evidence is missing. Configuring logging in advance is covered in the PowerShell Logging Detection Guide; this page assumes the incident has already happened.
Key takeaways
- Event 4104 is the richest source. Script block logging records the content PowerShell actually processed, including code generated at runtime after decoding, so it often shows the deobfuscated payload.
- PSReadLine history survives the session. Each user's
ConsoleHost_history.txtkeeps interactive commands across sessions; Clear-History does not delete it, but attackers can. - Transcripts show output, not just input. Where transcription was enabled, transcripts record what the attacker typed and what came back, which shows what they learned.
- Absence is evidence. A host with engine start events but no script block events, a deleted history file or a gap in the Operational log points to anti-forensics or a downgrade, and should be recorded as a finding.
- Correlate before concluding. No single artefact is complete; join script blocks, engine events, history, transcripts, process creation and logons on host, user and time.
The PowerShell artefact map
PowerShell evidence comes from the engine itself, from the PSReadLine module that powers the interactive console, from optional transcription, and from Windows process and logon telemetry around it. The table below is the working map for collection.
| Artefact | Location | What it shows | Depends on |
|---|---|---|---|
| Script block logging, Event 4104 | Microsoft-Windows-PowerShell/Operational (Windows PowerShell 5.1); PowerShellCore/Operational (PowerShell 7) | Content of every script block processed, including dynamically generated code | Script block logging policy; some suspicious blocks are logged automatically without it |
| Module logging, Event 4103 | Microsoft-Windows-PowerShell/Operational | Pipeline execution details: commands and parameter values for logged modules | Turn on Module Logging policy, with module names listed |
| Engine lifecycle, Events 400 and 403 | Windows PowerShell log | Engine start and stop, with host application command line and engine version | On by default |
| Pipeline execution, Event 800 | Windows PowerShell log | Pipeline execution details for modules with logging enabled | Module logging |
| Script start and stop, Events 4105 and 4106 | Microsoft-Windows-PowerShell/Operational | Invocation start and stop for script blocks | Script block invocation logging (high volume, often off) |
| PSReadLine history | %APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\<HostName>_history.txt, typically ConsoleHost_history.txt | Interactive command lines across sessions, in order, without timestamps | PSReadLine loaded in an interactive host |
| Transcripts | Each user's Documents folder by default, or the policy OutputDirectory | Commands typed and console output, with per-command timestamps if invocation headers are on | Turn on PowerShell Transcription policy or Start-Transcript in a profile |
| Process creation | Security Event 4688 with command line auditing, or EDR and Sysmon process events | powershell.exe, pwsh.exe and wsmprovhost.exe launches, parent process and command line | Process creation auditing with command line inclusion |
| Profiles | Per-user and all-users profile.ps1 files | Persistence: code that runs every time PowerShell starts | Always present if created |
Microsoft documents the Windows PowerShell log as readable and writable by users, and warns that it should not be relied on for security auditing because a malicious user could write false data or erase activity. Treat the Operational log and centrally forwarded copies as stronger evidence than the classic Windows PowerShell log.
Script block logging: reading Event 4104 in depth
Microsoft's about_Logging documentation describes Event 4104 as recording the content of each script block PowerShell processes, for interactive and automated use alike. Microsoft's PowerShell team blog explains why that matters for forensics: when a script block generates code at runtime, PowerShell logs the generated script block as well. An attacker who Base64-encodes a command and XOR-decrypts a second stage still leaves the decoded stage in 4104, because the engine has to process it as code.
Fields that matter
- ScriptBlockText: the code itself. Read it as text; never paste it into a live console.
- ScriptBlockId: a GUID shared by all parts of one script block. Use it to group fragments.
- MessageNumber and MessageTotal: large script blocks are split across several 4104 records. Reassemble by ScriptBlockId in MessageNumber order and confirm the count matches MessageTotal; a missing part means lost or cleared events.
- Path: the script file path when the block came from a file; blank for interactive or in-memory code.
- Security UserID and process ID: in the event's System section, linking the block to an account and a process for correlation with 4688 and logon events.
- Level: blocks that PowerShell judged suspicious are logged automatically, even when full script block logging is off. The PowerShell team describes this as a record of last resort, not a replacement for full logging.
Protected Event Logging
If the organisation enabled Protected Event Logging, 4104 content is encrypted with Cryptographic Message Syntax using a public key deployed to endpoints. Microsoft's documentation shows decryption with Unprotect-CmsMessage on a system holding the private key, which should be a central collector, not the endpoint. Request the decryption certificate from the logging owner early: without it, encrypted 4104 content is unreadable.
Reading script blocks safely
Script block content is hostile material. Analyse it in an isolated analysis environment, treat every string as text, and use the techniques in the Deobfuscating Malicious JavaScript and PowerShell guide when layers of encoding remain. Record hashes of exported logs before analysis.
Engine and module events: 400, 403, 800 and 4103
Engine lifecycle events are on by default. Microsoft's about_Eventlogs documentation lists engine start and stop and provider start and stop as logged by default, while command lifecycle events are off by default. That makes Events 400 and 403 present on most hosts even where nothing else was configured. Microsoft's PowerShell logging pages describe the channels and settings but do not list the event ID numbers, so confirm the IDs in this guide against your own logs and the Windows event reference.
- Event 400 (engine started): the HostApplication field holds the command line that started PowerShell, which often contains an encoded command, a download cradle or a script path. EngineVersion shows which PowerShell version ran. An EngineVersion of 2.0 on a host that has 5.1 is a classic downgrade to avoid script block logging, which only exists in later versions.
- Event 403 (engine stopped): pair with 400 to estimate session duration.
- Event 4103 and Event 800: module logging records pipeline execution, including parameter bindings, for the modules named in policy. Where 4104 shows the script, 4103 shows the commands and parameter values that actually executed.
Microsoft has announced the removal of PowerShell 2.0 from Windows 11 version 24H2 starting with an August 2025 release, and from Windows Server 2025 with a September 2025 release. Older systems in your estate may still have it, so check EngineVersion on every 400 event in scope.
PSReadLine history files
PSReadLine saves interactive command history per host to a file named after the host, for example ConsoleHost_history.txt for the standard console. On Windows, Microsoft documents the folder as $Env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine; on Linux and macOS it is under $XDG_DATA_HOME/powershell/PSReadLine or ~/.local/share/powershell/PSReadLine. Collect the file for every user profile, including service accounts and the built-in Administrator, and from Visual Studio Code host files where present.
What the file can and cannot tell you
- Order, not time: lines are in sequence but carry no timestamps. Anchor them using the file's modification time, matching 4104 events and transcripts.
- Interactive only: scripts run by file, scheduled tasks and non-interactive remoting generally do not appear.
- Sensitive lines filtered: Microsoft documents that PSReadLine excludes lines that look like they contain secrets. Before version 2.2.0 this matched strings such as password, asplaintext, token, apikey and secret; from 2.2.0 it uses the PowerShell syntax tree with an allowlist for SecretManagement cmdlets. A missing credential handling step may simply have been filtered.
- Easily removed: ATT&CK T1070.003 Clear Command History notes that Clear-History clears only the current session and does not remove ConsoleHost_history.txt, but that adversaries delete or edit the file. Check the file's metadata, NTFS change journal and volume shadow copies for earlier versions. See the Anti-Forensics Detection Guide.
Transcripts
Transcription records the commands typed and the output shown in the console. Microsoft's Start-Transcript documentation gives the default location as the user's Documents folder on Windows and the file name pattern PowerShell_transcript.<computername>.<random>.<timestamp>.txt. The Turn on PowerShell Transcription policy applies the same behaviour to every session and can redirect output to a central OutputDirectory, and the invocation header option adds a timestamp for each command.
- Where to look: every user's Documents folder, the OutputDirectory set in policy (check the policy value in the collected registry hive) and any central share.
- What they add: output reveals what the attacker learned (users, shares, credentials displayed) and failed commands they retried, which script blocks do not show.
- Integrity: Microsoft advises restricting access to a shared transcript directory so users cannot read others' transcripts. If permissions were loose, an attacker with access could have read or altered transcripts, which affects their evidential weight.
Collecting PowerShell evidence
- Preserve before you query: on a live host, export event logs and copy files before running any interactive PowerShell as an investigator, because your own commands write to the same logs and history files.
- Collect the logs as files: copy the EVTX files for Microsoft-Windows-PowerShell/Operational, Windows PowerShell and PowerShellCore/Operational from the winevt Logs folder, plus Security and System. Hash each file.
- Collect per-user artefacts: PSReadLine history files, transcripts, profile.ps1 files and recent script files from every profile.
- Collect configuration: registry hives that hold the PowerShell logging and transcription policies, so you can show what was and was not enabled at the time.
- Pull central copies: SIEM or collector copies of 4104 and 4103 events, which may survive local clearing and may hold decrypted protected events.
- Capture memory where justified: in-memory PowerShell runspaces and loaded scripts may hold content that never reached disk. See the Memory Forensics Guide.
For the wider Windows artefact set, see the Windows Forensic Artefacts Guide.
Reconstructing the timeline
Build the reconstruction around 4104 content and anchor everything else to it. The Forensic Timeline Analysis Guide covers tooling such as super-timelines; the PowerShell specific joins are below.
| Question | Primary source | Corroborating source |
|---|---|---|
| How did PowerShell start? | Event 400 HostApplication | Event 4688 or EDR parent process and command line |
| What code ran? | Event 4104 reassembled by ScriptBlockId | 4103 and 800 pipeline details, transcripts |
| What did the attacker type interactively? | PSReadLine history | Transcripts, 4104 with blank Path |
| What did they see? | Transcripts | Files written by the commands, network logs |
| Was it remote? | wsmprovhost.exe as the host process in process events | Logon events for the account, WinRM logs; see Windows Remote Management and WinRM/PowerShell Remoting Security Guide |
| Which identity ran it? | UserID on 4104, Subject on 4688 | Logon session IDs and logon type |
| Did they try to hide? | Gaps, EngineVersion 2.0, history file deletion | Log clearing events, policy changes in registry |
Step-by-step reconstruction
- Parse all PowerShell EVTX files into one table keyed by host, time, user, process ID and event ID.
- Reassemble 4104 fragments by ScriptBlockId and flag incomplete blocks.
- Deduplicate: the same script block can be logged more than once; keep the first occurrence time and a count.
- Link each 400 event's process ID to the 4104 and 4103 events from the same process, giving one session per engine instance.
- Map PSReadLine lines to 4104 entries with matching text to give them approximate timestamps.
- Join process creation to find the parent: Office applications, script hosts, scheduled tasks, services or wsmprovhost.exe each tell a different initial access or lateral movement story.
- Extract indicators (URLs, IPs, file paths, scheduled task names, registry keys, accounts) from decoded content and sweep the rest of the estate for them.
Where identity fits
PowerShell sessions in incidents frequently run under service accounts, automation accounts and stolen administrator credentials. The UserID in 4104 and the account in 4688 tell you which identity to contain. Look specifically for script blocks that read credentials (stored credential files, secret retrieval calls, token requests to cloud endpoints) and treat any secret visible in decoded content as compromised: rotate it, then search for its use elsewhere. Remote sessions also show which accounts had remoting rights, which feeds back into the PowerShell Security Guide recommendations on Just Enough Administration.
Spotting missing or tampered evidence
- Log clearing: Security Event 1102 and System Event 104 record log clearing (ATT&CK T1685.005 Clear Windows Event Logs). A cleared PowerShell Operational log shows as a gap with a clearing event.
- Logging disabled: changes to the ScriptBlockLogging or Transcription policy values in the registry around the incident window (ATT&CK T1685.001 Disable or Modify Windows Event Log covers related tampering).
- Downgrade: EngineVersion 2.0 in Event 400 with no matching 4104 activity.
- PowerShell without powershell.exe: ATT&CK T1059.001 notes that PowerShell can run through the System.Management.Automation assembly without invoking powershell.exe. Script block logging still applies to the engine, so 4104 events from an unusual process ID or host application are worth chasing.
- History tampering: a ConsoleHost_history.txt that is empty, recently recreated or shorter than its shadow copy versions.
Decision guidance: what to do with the evidence you have
- Full logging and central collection: use the SIEM copy as the primary source and local EVTX as corroboration; the central copy is harder for the attacker to alter.
- Defaults only: rely on 400 HostApplication, automatically logged suspicious 4104 blocks, PSReadLine history, process creation and memory. State clearly in the report that full script content may be missing.
- Small environments: manual review of a few hosts' EVTX and history files is practical. Large incidents need scripted parsing across hundreds of hosts and a fixed schema so results can be compared.
- Legal or regulatory exposure: preserve hashes, chain of custody and the exact policy state, because whether logging was enabled may itself be questioned.
Measuring readiness
- Script block coverage: percentage of Windows endpoints and servers sending 4104 to central collection.
- Transcription coverage: percentage of administrative hosts writing transcripts to a protected central directory.
- Legacy engine presence: number of hosts where PowerShell 2.0 is still installed, target zero.
- Retention: days of PowerShell events retained centrally, compared with your typical detection lag.
- Time to reconstruct: hours from evidence collection to a reviewed PowerShell timeline in exercises and real cases.
Common failure patterns
- Investigating on the live host with PowerShell first: the responder's own commands overwrite history and add noise to the logs before collection.
- Reading only the first fragment: analysing one 4104 record of a split script block and missing the payload in later parts.
- Ignoring the classic log: skipping Event 400 because script block logging was off, and missing the encoded command line it held.
- Collecting one profile: taking the history file for the compromised user only, and missing service account and administrator histories.
- Losing protected events: collecting encrypted 4104 events but never obtaining the decryption key from the logging owner.
- Treating no evidence as no activity: concluding PowerShell was not used because 4104 is empty, without checking for downgrade or clearing.
Framework mapping
| Framework | Reference | Relevance |
|---|---|---|
| MITRE ATT&CK | T1059.001 PowerShell; T1070.003 Clear Command History; T1685.005 Clear Windows Event Logs; T1685.001 Disable or Modify Windows Event Log | Techniques the artefacts reveal and the anti-forensics to check for |
| NIST SP 800-53 Rev 5 | AU-12 Audit Record Generation; AU-9 Protection of Audit Information; IR-4 Incident Handling | Generating and protecting PowerShell logs; using them in incident analysis |
| NIST CSF 2.0 | PR.PS-04; RS.AN-03 | Log records available for monitoring; analysis to establish what happened |
| CIS Controls v8.1 | Control 8 Audit Log Management; Control 17 Incident Response Management | Command-line and script logging, central collection and response use |
| ISO/IEC 27001:2022 Annex A | A.8.15 Logging; A.5.28 Collection of evidence | Log generation and protection; forensic evidence handling |
Practitioner checklist
- Export PowerShell EVTX files, history files, transcripts and profiles before running any PowerShell on the host.
- Hash every collected file and record the PowerShell logging policy state from the registry.
- Reassemble 4104 script blocks by ScriptBlockId and check MessageNumber against MessageTotal.
- Read every Event 400 HostApplication and EngineVersion, and flag any 2.0 engine use.
- Collect PSReadLine history for every profile, including service accounts, and check shadow copies for deleted versions.
- Pull central SIEM copies and obtain the Protected Event Logging decryption key where used.
- Correlate script blocks with process creation and logon events to identify parent process, identity and remote origin.
- Record gaps, clearing events and policy changes as findings, not just limitations.
- Rotate every credential that appears in decoded script content.
Standards and references
- Microsoft Learn: about_Logging (Windows PowerShell 5.1)
- Microsoft Learn: about_Logging_Windows (PowerShell 7)
- Microsoft Learn: about_EventLogs
- Microsoft Learn: about_PSReadLine
- Microsoft Learn: Start-Transcript
- Microsoft Learn: about_Group_Policy_Settings
- MITRE ATT&CK: PowerShell (T1059.001)
- MITRE ATT&CK: Clear Command History (T1070.003)
Related NHI Mgmt Group resources: PowerShell Logging Detection Guide · T1059 Command and Scripting Interpreter Defensive Guide · Digital Forensics (DFIR) Guide · Windows Forensic Artefacts Guide