PowerShell and Command-Line Logging
What you'll learn: How to capture and analyze PowerShell scripts and command-line activity to detect malicious behavior on Windows systems.
Why PowerShell Logging Matters
PowerShell is one of the most powerful administrative tools on Windows—and attackers know it. Without proper logging, malicious scripts can execute invisibly. Think of PowerShell logging as installing security cameras in every room of your house: suddenly, you can see exactly what happened, when, and by whom.
Core Logging Types
Script Block Logging captures the actual content of PowerShell scripts and commands as they execute. When enabled (via Group Policy under Administrative Templates > Windows Components > Windows PowerShell), every script block—even obfuscated or dynamically generated code—gets logged to Event ID 4104. This is your strongest defense against fileless malware.
Transcription Logging records complete PowerShell session input and output to text files, creating a chronological transcript. Enable it through the same Group Policy path. It's like having a court reporter documenting every command and its result.
Module Logging tracks when PowerShell modules load and execute. Configure it to log specific modules you want to monitor closely (or use * for all modules). Events appear as ID 4103.
Process Command-Line Auditing isn't PowerShell-specific but captures the full command line of every process launched system-wide (Event ID 4688). This catches both PowerShell and traditional cmd.exe activity, revealing suspicious parameters like -EncodedCommand or IEX (New-Object Net.WebClient).DownloadString().
Analysis Approach
Search your Windows Event Logs for encoded commands, base64 strings, unusual network connections initiated via PowerShell, or downloads from suspicious domains. Correlate these with user logins and file access events you've learned to monitor.
Key Takeaway: Enable script block logging, transcription, module logging, and command-line auditing to gain comprehensive visibility into PowerShell and shell activity—transforming Windows systems from blind to observable and catching script-based attacks before they succeed.