Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is PowerShell Script Block Logging?

Script block logging records the PowerShell code that actually runs, after decoding and deobfuscation, as Event ID 4104. It is the single most valuable Windows log for detecting attacker tooling.

Illustration for the cybersecurity term PowerShell Script Block Logging
Home / Blog / Cybersecurity Terms / What Is PowerShell Script Block Logging?
17 November 2026

What Is PowerShell Script Block Logging?

What Is PowerShell Script Block Logging?

PowerShell is installed on every Windows machine, signed by Microsoft, and capable of downloading and executing code entirely in memory. That combination has made it a favourite of intruders for a decade. Script block logging is Microsoft’s answer: it records the contents of each block of PowerShell code at the moment it is compiled for execution, after any encoding or obfuscation has been undone, and writes it to the Windows event log as Event ID 4104.

The deobfuscation is the important part. An attacker who launches powershell.exe -enc SQBFAFgA... leaves a command line that says nothing. Script block logging records what that Base64 decoded into, which is usually a complete attack tool.

Turning It On

Script block logging requires PowerShell 5.0 or later and is configured through Group Policy at Computer Configuration, Administrative Templates, Windows Components, Windows PowerShell, “Turn on PowerShell Script Block Logging”. It can equally be set through Intune or directly in the registry:

HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
    EnableScriptBlockLogging       (REG_DWORD) = 1
    EnableScriptBlockInvocationLogging = 0

Leave invocation logging disabled. It records the start and stop of every block execution and produces a volume of events that will swamp a collector for almost no additional detection value.

Events land in the Microsoft-Windows-PowerShell/Operational channel. The default channel size is far too small for a server that uses PowerShell for administration, so raise it and forward the events off the host. Long scripts are split across several 4104 events carrying MessageNumber and MessageTotal fields, and any detection logic needs to reassemble them before matching, or it will miss strings that straddle a boundary.

Two related features are worth enabling alongside it. Module logging (Event ID 4103) records pipeline execution details, and transcription writes a readable session transcript to a protected file share, which is invaluable when an investigation needs to see what an administrator or an attacker actually typed in sequence.

What to Hunt For

Attacker PowerShell has a recognisable vocabulary. Useful starting points for detection rules include:

Write these as portable detection logic rather than vendor queries where you can; the public Sigma rule repository already contains a large body of tested PowerShell rules that convert to most SIEM query languages.

The Downgrade Bypass

Script block logging exists only in PowerShell 5 and later. An attacker who runs powershell.exe -Version 2 on a host where the PowerShell 2.0 engine is still present drops back to a runtime with no script block logging and no AMSI integration, and does so silently. Remove the Windows optional feature PowerShell 2.0 Engine across the estate, and alert on Event ID 400 showing EngineVersion=2 wherever it survives. Constrained language mode and application control through WDAC remove further avenues, though they take planning.

Secrets in the Logs

Script block logging captures everything the script contained, including any password, API key, or connection string typed or embedded in the code. Those events are then forwarded to a collector and retained for months, which converts a bad scripting habit into a durable credential exposure. Restrict read access to the operational channel, keep the SIEM index holding 4104 events under tighter access control than general logs, and treat the discovery of a plaintext secret in a script block as an incident requiring rotation. It is also worth noting that Windows logs blocks it considers suspicious at warning level even when the policy is disabled, so a handful of 4104 events appearing on an unconfigured host is expected behaviour rather than evidence the setting was on.

Script block logging pairs naturally with Sysmon process telemetry and the wider Windows event log set: Sysmon tells you a PowerShell process started and who its parent was, and 4104 tells you what it then did. At Privia Security, we tune this kind of Windows detection coverage as part of our SOC maturation services.

FAQ – Frequently Asked Questions

Does Script Block Logging Slow Machines Down?

The performance cost is minor on normal workloads because logging happens when a block is compiled, not continuously. The practical cost is event volume on hosts that script heavily, such as management servers and build agents. Keep invocation logging off, raise the channel size, and filter noisy known-good scripts at collection rather than disabling the policy on those hosts.

What Is the Difference Between 4104 and 4688?

Event ID 4688 records that a process started and, with command line auditing enabled, the command line used to start it. Event ID 4104 records the PowerShell code that ran inside that process, decoded and deobfuscated. An encoded command looks meaningless in 4688 and fully readable in 4104, which is why both are needed.

Can Attackers Disable Script Block Logging?

An attacker with administrative rights can change the registry setting or clear the channel, which is why forwarding events off the host matters more than the setting itself. More common is avoidance rather than disabling: downgrading to PowerShell 2.0, patching the logging provider in memory, or using a different scripting host entirely. Remove the version 2 engine and alert on configuration changes.

Should We Enable It on Workstations as Well as Servers?

Yes. Workstations are where phishing payloads land and where most attacker PowerShell first runs, and they typically generate far fewer events than administrative servers. If volume is a concern, enable it everywhere, retain workstation events for a shorter period, and keep server events longer. Partial deployment creates exactly the blind spot an attacker needs.

Related Terms

You May Be Interested In These

What Is PowerShell Empire?

Cybersecurity Terms

17 November 2026

What Is PowerShell Empire?

Read More
What Is the USN Journal?

Cybersecurity Terms

17 November 2026

What Is the USN Journal?

Read More