Event ID 4104: Creating Scriptblock text

Event ID 4104, "Creating Scriptblock text", is written to the Microsoft-Windows-PowerShell/Operational log with the text of PowerShell code as it runs, after PowerShell has decoded it, which makes it the best record of what an attacker did in PowerShell.

Microsoft-Windows-PowerShell/Operational logPowerShellChecked 1 December 2026

What event 4104 records

PowerShell compiles code in blocks: a typed command, a script file, a function, or code decoded from Base64 or built at run time. Script block logging writes each block's text as 4104, with the script path if there is one. Long scripts are split across several 4104 events that share a ScriptBlock ID and carry "Message number X of Y".

Because logging happens after decoding, powershell -enc <base64> and code assembled from strings show up in readable form, which is the main reason 4104 matters.

Enabling it, and what is logged anyway

Full script block logging is enabled by Group Policy: Administrative Templates › Windows Components › Windows PowerShell › **Turn on PowerShell Script Block Logging** (registry EnableScriptBlockLogging = 1 under HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging).

Even when it is off, PowerShell 5 and later log script blocks that contain commonly abused content (certain APIs, reflection, encoding tricks) as 4104 with level Warning. So a machine with no policy can still hold the most suspicious blocks. Two related logs help: 4103 (module logging, with pipeline details) and the PowerShell transcription files, if transcription is enabled.

Reassembling long script blocks

A script longer than one event can hold is split across several 4104 events with the same ScriptBlock ID, each labelled "Message number X of Y". Read them in order by message number, not by timestamp, to get the full script. Only the first part of a block may contain the parameters or the decoded payload, so a search that matches one part should always pull its siblings. Arcsentry keeps each part as its own record with the ScriptBlock ID in the event data, so grouping by process_powershell_script_block_id puts a script back together.

The PowerShell operational log is small by default, and verbose script block logging fills it quickly on busy systems. Increase its size wherever the policy is turned on.

Investigating with 4104, step by step

  • Pull every 4104 in the incident window from the affected hosts, including Warning-level ones written without the policy.
  • Group parts by ScriptBlock ID and read each script in full; one decoded block often contains the URL, file path or credentials the rest of the investigation needs.
  • Match scripts to their process: PowerShell operational event 4100 errors and 40961/40962 (console start) and Security 4688 show which powershell.exe ran them and under which session.
  • Extract indicators (addresses, domains, file paths, registry keys) and search every host for them.
  • Compare with the PSReadLine history file (ConsoleHost_history.txt) where it survives; it records typed commands without times, while 4104 records them with times.

Event 4104 fields

The fields an investigator reads first, what they mean, and where Arcsentry stores them.

FieldMeaningArcsentry field
MessageNumber and MessageTotalPosition of this part when a block is split across events.event data
ScriptBlockTextThe code itself.event data
ScriptBlockIdGUID shared by all parts of one block.event data
PathThe script file, if the block came from one.event data
LevelVerbose for normal logging, Warning for automatically logged suspicious blocks.event data

In Arcsentry the script text is readable as process_powershell_script_block, with the script block ID as process_powershell_script_block_id.

What event 4104 proves, and what it does not

It shows

  • That this PowerShell code was compiled to run on this computer at this time.

It does not show

  • That it completed successfully, or what its output was (transcripts record output).
  • Anything run in other interpreters, or in PowerShell 2.0, which has no script block logging.

Attacker activity it reveals

Decoded download cradles

IEX with Net.WebClient, Invoke-WebRequest or Start-BitsTransfer fetching a script from an IP address or a paste site. MITRE ATT&CK T1059.001

Obfuscation

Blocks full of character arithmetic, string reversal, -join, [char] casts or FromBase64String; often logged at Warning level automatically. MITRE ATT&CK T1027

Discovery and collection

whoami, Get-LocalUser, Get-ADUser, findstr over user folders for "password", Compress-Archive of document folders.

Clean-up

Remove-Item of staged files and of the PSReadLine history file (ConsoleHost_history.txt), Clear-EventLog. MITRE ATT&CK T1070

In a real investigation: Halden Freight office intrusion

On HF-WS01 in our Windows lab case, 4104 recorded the attacker's interactive PowerShell session after the RDP logon (times UTC):

  • 22:07:29: whoami /all, the first discovery command.
  • 22:08:23: findstr searching a.berg's Desktop and Documents text files for "pw" and "password", followed by Get-Content of a file it found.
  • 22:10:09: Compress-Archive of C:\Users\a.berg\Documents\Finance\* into C:\Users\Public\Documents\q4-close.zip.
  • 22:14:06: Remove-Item of q4-close.zip.
  • 22:14:16: deletion of the PSReadLine history file, an attempt to remove the typed-command record. 4104 had already captured the commands.

Finding event 4104 in Arcsentry

Arcsentry parses every channel in Windows\System32\winevt\Logs, whether it comes from an Arcsentry Collector archive, a KAPE or Velociraptor collection, or a disk image. Microsoft-Windows-PowerShell/Operational log records are the event type evtx_microsoft_windows_powershell_operational. In Hunt, with that event type selected:

filter event_code == "4104"
derive {code = process_powershell_script_block}
filter code ~= "(?i)(iex|invoke-expression|downloadstring|webclient|invoke-webrequest|frombase64string|compress-archive|remove-item|consolehost_history|-enc)"
select {timestamp, user_name, code}
sort {timestamp}

Script blocks with download, decoding, archiving and clean-up patterns, in order.

Or ask in plain English, for example "show event 4104 on every host, oldest first", and Arcsentry shows the AQL it wrote before it runs. The AQL reference lists the operators used here, and the AI investigator reads the same events, citing each one by its event ID when it reports a finding.

Related event IDs

All events by investigation question: Windows security event IDs for incident response. Logon types in full: Windows logon types. The log files themselves: Windows event logs.

Frequently asked

Does event 4104 show the output of a command?

No. It records the code that ran, not its results. PowerShell transcription, if enabled, writes both the commands and their output to text files, which Arcsentry parses as PowerShell transcripts.

Where are PowerShell script block logs stored?

In the Microsoft-Windows-PowerShell/Operational event log, the file Microsoft-Windows-PowerShell%4Operational.evtx in C:\Windows\System32\winevt\Logs. Windows PowerShell 5.1 and PowerShell 7 write to their own operational logs.

Can attackers avoid script block logging?

Some try: running PowerShell version 2 (which has no script block logging) where it is still installed, tampering with the logging settings in memory, or clearing the log. Each of these leaves its own traces, and removing PowerShell 2.0 closes the first route.

How do I enable PowerShell script block logging?

Group Policy: Administrative Templates › Windows Components › Windows PowerShell › Turn on PowerShell Script Block Logging. Events go to Microsoft-Windows-PowerShell/Operational as 4104.

What is the difference between event 4103 and 4104?

4104 records the text of each script block as it is compiled. 4103 (module logging) records pipeline execution details, including parameters passed to commands. Together they show what was run and how.

Is PowerShell logged even if script block logging is off?

Partly. PowerShell 5 and later log script blocks with suspicious content automatically, as 4104 at Warning level. Everything else needs the policy.

Sources

  • Microsoft Learn: about_Logging_Windows (PowerShell)
  • MITRE ATT&CK: T1059.001 PowerShell; T1027 Obfuscated Files or Information
  • Venema Labs lab case: Halden Freight office intrusion, HF-WS01 PowerShell operational log

Checked 1 December 2026 by Venema Labs against Microsoft's audit documentation and, where an example is shown, the named lab case. Field availability varies by Windows version.

Find event 4104 across every host in minutes.

Load your collections, ask what happened, and check every finding against the event behind it. Free for 7 days.

Request a trial