Written by Ruben Selby, founder and penetration tester at Wolfcore. Last reviewed 21 November 2026.
In one sentence: Event ID 4104 is a Windows log entry that saves the text of the PowerShell commands that ran on a computer, so you can see what an attacker or a script actually did.
What it is
PowerShell is the built-in Windows command and scripting tool. IT teams use it every day, and attackers like it for the same reason: it is already there. Event 4104 is written when script block logging is on. Microsoft’s documentation says that when you enable it, PowerShell records the content of all script blocks that it processes, whether they are run interactively or through automation.
A script block is a chunk of PowerShell code. The log holds the code itself, not only the name of the program that started it.
Microsoft’s PowerShell 7 documentation lists the event as ID 4104 with level Verbose in the PowerShellCore/Operational log. The same page shows the decryption example reading event 4104 from Microsoft-Windows-PowerShell/Operational, which is the log used by Windows PowerShell 5.1, the version built into Windows.
How it works
- You switch on script block logging, by Group Policy or a registry setting.
- Any new PowerShell session then logs script blocks as it processes them.
- Each one appears as event 4104 in the Operational log.
- You collect those logs centrally and search them.
The Microsoft page offers three ways to switch it on for PowerShell 7 (check the 5.1 documentation for the Windows PowerShell equivalent): Group Policy (“Turn on PowerShell Script Block Logging”, under Administrative Templates), a registry value EnableScriptBlockLogging set to 1, or the powershell.config.json file.
One important warning from Microsoft: with script logging on, credentials or other sensitive data used by a script can be written to the event log. Microsoft recommends Protected Event Logging, which encrypts sensitive log content, when script block logging is used for anything beyond diagnostics.
Who it affects and how badly
Event 4104 is a defender’s tool, so the question is what happens when it is missing.
- Sole trader to 10 staff: you may have no central logging. If something odd happens, there is nothing to read afterwards.
- 10 to 50 staff (accountancy, legal, schools, charities): one server and a few PCs. Without 4104 you can tell a PowerShell window opened, but not what it did.
- 50 to 250 and regulated firms (healthcare, fintech, insurance, telecoms, MSPs): investigators, insurers and regulators will ask what happened and what data was touched. Without records the answer is “we do not know”, which can mean a longer shutdown while you rebuild and a weaker position with clients and regulators.
Real examples
Microsoft’s own documentation, rather than an incident, is the best primary source here.
- Microsoft’s warning on log contents: the PowerShell documentation states that logged credentials can give an attacker information to extend their reach if the machine is compromised. Source: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_logging_windows?view=powershell-7.6
No named victim is cited here, because no primary report tying Event ID 4104 to a confirmed incident was used.
Rules and regulators
The UK NCSC’s “Introduction to logging for security purposes” says logging is the foundation of security monitoring. It asks whether you can answer what happened, what the impact is and whether controls are working. It says to protect logs from tampering, and recommends holding logs for a minimum of 6 months. It lists process execution and Microsoft EVTX logs as sources for the question “has anyone executed a suspect binary”. The guidance is UK-led, but the questions apply anywhere, and it also points to Windows Event Forwarding for central collection. Source: https://www.ncsc.gov.uk/guidance/introduction-logging-security-purposes
What we check on a test
Our method, not a finding from any client.
- Whether script block logging is configured by policy on workstations and servers, and for both Windows PowerShell 5.1 and PowerShell 7.
- Whether the Operational log is large enough to hold days of data, and whether it is forwarded off the machine.
- Whether PowerShell activity during our testing shows up where your team looks.
- Whether Protected Event Logging is used, and who can read the logs.
- Whether older PowerShell versions are still installed, so you know what your logging policy needs to cover.
How to detect it
- In Event Viewer, open Applications and Services Logs, Microsoft, Windows, PowerShell, Operational, and filter for Event ID 4104.
- Long scripts can be split across several 4104 events, so read all the parts together before judging them.
- Look at what the script does, not just that PowerShell ran. Downloading content, decoding hidden text and running text as code deserve a second look. Legitimate admin scripts also do these things, so ask who ran it and why.
- Match the time with a process creation event (Event ID 4688) and with logon events such as 4624.
- Check for persistence in scheduled tasks (4698) and new services (7045).
How to fix or prevent it
- Turn on script block logging by Group Policy for all Windows PowerShell and PowerShell 7 machines.
- Increase the size of the Operational log so it does not roll over in hours.
- Forward the logs to a central place. NCSC advises central collection and protection from tampering.
- Enable Protected Event Logging so that secrets in scripts are encrypted in the log, as Microsoft recommends.
- Restrict who can read these logs and who can clear them. Clearing is itself an event to watch (Event ID 1102).
- Review alerts and test that a harmless test command shows up end to end.
Related terms
windows event id 4688 process creation, windows event id 4698 scheduled task created, windows event id 7045 service installed, windows event id 4624 successful logon, indicators of compromise, port 5985 5986 winrm
Back to the detection and response hub.
FAQ
Is script block logging on by default? Microsoft’s documentation describes enabling it by policy, registry or configuration file, which indicates it is something you switch on.
Why can the log be dangerous? Microsoft warns credentials and other sensitive data used by a script can be written to the log. Use Protected Event Logging and limit access.
Where do I find the events? In the PowerShell Operational log, as Event ID 4104. PowerShell 7 uses the PowerShellCore Operational log, and Windows PowerShell uses the Microsoft-Windows-PowerShell Operational log.
How Wolfcore helps
Wolfcore’s vulnerability management and SOC monitoring keep watch for this after the test is over. See SOC monitoring.
Wolfcore
Would your staff click a phishing email?
Run a real, safe phishing test on your team with Phishy. Free for 14 days, up to 10 staff, no card. We help you set it up.
Start a free phishing testFree website security scanor book a 30 minute call