An error occurred during PowerShell script execution. ErrorRecord and ScriptName are key.
Attack tools generating errors during execution — useful for detecting failed attack attempts. Encoded commands that fail to decode properly. Also useful for detecting when defenses blocked execution.
Alert: errors from suspicious scripts or encoded commands. Look for access denied errors on sensitive paths from unexpected processes.
ScriptBlockTextPathHostApplication Starting points — adapt the log source, projected fields and thresholds for your environment.
Event
| where EventLog == "Microsoft-Windows-PowerShell/Operational" and EventID == 4100 // PowerShell script execution error
// EventData holds: ScriptBlockText, Path, HostApplication
| project TimeGenerated, Computer, RenderedDescription
| sort by TimeGenerated desc
index=* sourcetype="WinEventLog:Microsoft-Windows-PowerShell/Operational" EventCode=4100
| stats count earliest(_time) as first_seen latest(_time) as last_seen by ComputerName
| sort - count `# PowerShell script execution error — add EventData fields: ScriptBlockText, Path, HostApplication`
PowerShell script execution error. An error occurred during PowerShell script execution. ErrorRecord and ScriptName are key.
Event 4100 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).
Alert: errors from suspicious scripts or encoded commands. Look for access denied errors on sensitive paths from unexpected processes.