PowerShell logging is off
AdvisoryW09Windows PCs and serversTurn on script block logging so PowerShell commands an attacker runs are…
What is the risk
Many attacks now run only PowerShell commands with no files. Without logs you cannot tell later what happened.
This is an advisory item. It does not block anything but leaves a trail if you are breached.
How to check
Windows PowerShell (admin)
Get-ItemProperty 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging' -ErrorAction SilentlyContinueEnableScriptBlockLogging = 1 means on. No output means off.
How to fix
Windows PowerShell (admin)
New-Item -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging' -Force
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging' -Name EnableScriptBlockLogging -Value 1 -Type DWord
wevtutil sl Microsoft-Windows-PowerShell/Operational /ms:104857600The last line grows the log to 100 MB so entries last longer. With group policy: Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell > Turn on PowerShell Script Block Logging.
How to prevent it
- Forward logs to another server so they survive even if an attacker clears them.
Check again after fixing
Windows PowerShell (admin)
Get-WinEvent -LogName 'Microsoft-Windows-PowerShell/Operational' -MaxEvents 20 | Where-Object Id -eq 4104Events with ID 4104 mean logging works.
Run the downloaded check again and make sure this item passes.