End of a multi-part script block logging sequence.
Use with 4104 to reassemble multi-part script blocks.
No standalone alerting. Correlate with 4104 via ScriptBlockId.
ScriptBlockTextPathHostApplication Starting points — adapt the log source, projected fields and thresholds for your environment.
Event
| where EventLog == "Microsoft-Windows-PowerShell/Operational" and EventID == 4106 // Script block end (final execution)
// EventData holds: ScriptBlockText, Path, HostApplication
| project TimeGenerated, Computer, RenderedDescription
| sort by TimeGenerated desc
index=* sourcetype="WinEventLog:Microsoft-Windows-PowerShell/Operational" EventCode=4106
| stats count earliest(_time) as first_seen latest(_time) as last_seen by ComputerName
| sort - count `# Script block end (final execution) — add EventData fields: ScriptBlockText, Path, HostApplication`
Script block end (final execution). End of a multi-part script block logging sequence.
Event 4106 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).
No standalone alerting. Correlate with 4104 via ScriptBlockId.