4104

Script Block Logging: Full script block execution captured

PowerShell Script Block Logging recorded the complete, un-obfuscated code block of an executing script.

Event ID 4104 (`Microsoft-Windows-PowerShell/Operational`) is the single most valuable event for hunting PowerShell attacks. When enabled, PowerShell automatically captures and logs the full text of every script block (`ScriptBlockText`), including scripts executed from memory, base64 payloads after de-obfuscation (`-EncodedCommand`), and interactive commands. Even when not explicitly enabled via GPO, PowerShell 5.1+ automatically logs `4104` events whenever it detects suspicious API calls or keywords (`Script Block Auto-Log`).

Failure Reason / Root Cause:

Execution of PowerShell script block (`ScriptBlock ID` & `ScriptBlockText` captured).

CategoryPowerShell
Audit typeSuccess Audit
SeverityCritical
Applies toWindows Server 2016, 2019, 2022 / Windows 10, 11
Keywords4104, powershell script block logging, scriptblocktext, encodedcommand deobfuscated, amsi, powershell hunting
Raw Event XML snippet
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Microsoft-Windows-Security-Auditing" Guid="{54849625-5478-4994-A5BA-3E3B0328C30D}" />
    <EventID>4104</EventID>
    <Version>0</Version>
    <Level>0</Level>
    <Task>12544</Task>
    <Opcode>0</Opcode>
    <Keywords>0x8020000000000000</Keywords>
    <TimeCreated SystemTime="2026-07-17T09:54:44.854Z" />
    <EventRecordID>1048576</EventRecordID>
    <Correlation />
    <Execution ProcessID="612" ThreadID="1024" />
    <Channel>Security</Channel>
    <Computer>DC01.enterprise.internal</Computer>
    <Security />
  </System>
  <EventData>
    <Data Name="SubjectUserSid">S-1-5-18</Data>
    <Data Name="SubjectUserName">SYSTEM</Data>
    <Data Name="SubjectDomainName">NT AUTHORITY</Data>
    <Data Name="SubjectLogonId">0x3e7</Data>
    <!-- Event telemetry fields specific to Script Block Logging: Full script block execution captured -->
  </EventData>
</Event>

MITRE ATT&CK mapping

IDTechniqueTactic
T1059.001Command and Scripting Interpreter: PowerShellExecution
T1027Obfuscated Files or InformationDefense Evasion

Recommended actions

Related events