4104 PowerShell log · Script Block Logging high severity high volume

PowerShell Event ID 4104 — Script block logging — script block recorded

The complete text of a PowerShell script block is recorded. Applies to PowerShell v5+. Includes auto-triggered logging for suspicious content even when not globally enabled (suspicious script block recording).

Why event 4104 matters

The gold standard for PowerShell detection. Captures: full decoded script content (even after deobfuscation), encoded commands expanded, AMSI bypass attempts, complete attack tool code (even when loaded in-memory). Script block logging auto-triggers for suspicious patterns even without explicit policy. Reveals the actual malicious PowerShell regardless of obfuscation layers.

How to detect it

MUST ENABLE: HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging. Alert: MessageNumber=1 (first block) with suspicious content — Invoke-Expression, IEX, [Reflection.Assembly]::Load, encoded payloads. Alert: known attack strings (mimikatz, invoke-shellcode, amsiutils, bypass). Alert: long random-character strings (obfuscated code). This is the most valuable PowerShell logging event.

Log source
Microsoft-Windows-PowerShell/Operational
Enable PowerShell Module Logging and Script Block Logging via GPO (Administrative Templates → Windows PowerShell).
Fields to pivot on
ScriptBlockTextPath

MITRE ATT&CK mapping

Tactic Technique
Execution PowerShell (T1059.001)
Defense Evasion Obfuscated Files or Information (T1027)

Detection queries

Starting points — adapt the log source, projected fields and thresholds for your environment.

Sigma rule
title: Suspicious PowerShell Script Block Content
status: stable
description: Script block logging captures malicious PowerShell patterns
author: theadminstack.com
date: 2026/05/16
logsource:
    product: windows
    service: powershell
detection:
    selection:
        EventID: 4104
        ScriptBlockText|contains:
            - 'Invoke-Mimikatz'
            - 'Invoke-Shellcode'
            - 'AmsiUtils'
            - 'amsiContext'
            - 'bypass'
            - 'Invoke-ReflectivePEInjection'
            - '[Reflection.Assembly]::Load'
    condition: selection
falsepositives:
    - Security testing and authorized red team operations
level: high
tags:
    - attack.execution
    - attack.t1059.001
    - attack.defense_evasion
Sentinel / Defender KQL
Event
| where EventLog == "Microsoft-Windows-PowerShell/Operational" and EventID == 4104   // Script block logging — script block recorded
// EventData holds: ScriptBlockText, Path
| project TimeGenerated, Computer, RenderedDescription
| sort by TimeGenerated desc
Splunk SPL
index=* sourcetype="WinEventLog:Microsoft-Windows-PowerShell/Operational" EventCode=4104
| stats count earliest(_time) as first_seen latest(_time) as last_seen by ComputerName
| sort - count   `# Script block logging — script block recorded — add EventData fields: ScriptBlockText, Path`
Hunt event 4104 in Sentinel/Defender →
Build a KQL query for this event in the KQL Query Builder.
Search all event IDs →
Open the interactive Windows Event ID lookup.

References

Related Script Block Logging events

4105 Script block start (first execution) 4106 Script block end (final execution)

Frequently asked questions

What is PowerShell Event ID 4104?

Script block logging — script block recorded. The complete text of a PowerShell script block is recorded. Applies to PowerShell v5+. Includes auto-triggered logging for suspicious content even when not globally enabled (suspicious script block recording).

Which log records event 4104?

Event 4104 is written to the Microsoft-Windows-PowerShell/Operational channel by Microsoft-Windows-PowerShell. Enable PowerShell Module Logging and Script Block Logging via GPO (Administrative Templates → Windows PowerShell).

What MITRE ATT&CK techniques map to event 4104?

Event 4104 is associated with: PowerShell (T1059.001), Obfuscated Files or Information (T1027).

How do you detect activity around event 4104?

MUST ENABLE: HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging. Alert: MessageNumber=1 (first block) with suspicious content — Invoke-Expression, IEX, [Reflection.Assembly]::Load, encoded payloads. Alert: known attack strings (mimikatz, invoke-shellcode, amsiutils, bypass). Alert: long random-character strings (obfuscated code). This is the most valuable PowerShell logging event.