PowerShell Commands
Get-WinEvent¶
View all events in the live system Event Log:
View all events in the file example.evtx, format list (fl) output:
View all events in example.evtx, format GridView output:
Perform long tail analysis of example.evtx:
Pull events 7030 and 7045 from system.evtx:
Same as above, but use the live system event log:
Search for events containing the string "USB" in the file system.evtx:
'grep'-style search for lines of events containing the case insensitive string "USB" in the file system.evtx:
Pull all errors (level=2) from application.evtx:
Pull all errors (level=2) from application.evtx and count the number of lines ('wc'-style):
Export Event Logs to CSV format
# Define the path to the directory where your event log files are stored
$logDirectory = "patch to log files"
# Loop through each event log file in the directory
Get-ChildItem $logDirectory -Filter *.evtx | ForEach-Object {
$logPath = $_.FullName
# Define the output path for the CSV file
$csvPath = "$logDirectory\$($_.BaseName).csv"
# Export the event log to a CSV file
Get-WinEvent -Path $logPath | Select-Object * -ExcludeProperty ContainerLog | Export-Csv $csvPath -NoTypeInformation
}
AppLocker¶
Pull all AppLocker logs from the live AppLocker event log (requires Applocker):
Search for live AppLocker EXE/MSI audit events: "(EXE) was allowed to run but would have been prevented from running if the AppLocker policy were enforced":
EMET¶
Pull all EMET logs from the live Application Event log (requires EMET):
Get-WinEvent -FilterHashtable @{logname="application"; providername="EMET"}
```
Pull all EMET logs from a saved Application Event log (requires EMET):
```powershell
Get-WinEvent -FilterHashtable @{path="application.evtx"; providername="EMET"}
Sysmon¶
Pull all Sysmon logs from the live Sysmon Event log (requires Sysmon and an admin PowerShell):
Windows Defender¶
Pull all live Windows Defender event logs
Get-WinEvent -FilterHashtable @{logname="Microsoft-Windows-Windows Defender/Operational";id=1116,1117}
References¶
SANS PowerShell Reference
SANS PowerShell Reference GitHub
Revision History¶
- 20230127 - Initial creation