Parsing CSV and JSON Event Exports in PowerShell
Analysts rarely read Windows event logs on the machine that wrote them. Events arrive as exports: a CSV from Get-WinEvent … | Export-Csv, JSON lines from a log shipper or a SIEM query, an EDR's process-tree download. The work is the same each time: load the records as objects, pull the interesting values out of nested fields, group and filter them, and write a short, reproducible answer. This lesson does that in PowerShell with a JSON export of process-creation events and a CSV of logons, all synthetic, from lab hosts under lab.test. The event IDs themselves are explained in The Windows Registry and Event Log, which already counted failed logons from a CSV; here the data is nested and the question is about processes.
Definitions
- Event 4688 (Security log, "A new process has been created"): new process name, parent process name, command line (when the policy "Include command line in process creation events" is on), account.
- Sysmon event 1 (Process Create): the same plus hashes, parent command line and a process GUID; preferred where Sysmon is installed.
- Event 4624 (successful logon) with
LogonType: 2 interactive, 3 network, 10 remote interactive (RDP). ConvertFrom-Json: turns JSON text intoPSCustomObjects; nested objects become nested properties ($e.Event.Data.CommandLine).- Calculated property:
@{Name='X'; Expression={ … }}inSelect-Objectadds a column computed from each object.
Suspicious process trees from a JSON export
The export holds one JSON object per line, in a nested shape like many log shippers produce. The script flattens it, then applies three hunting rules: an Office program starting a shell, an encoded PowerShell command (decoded on the spot), and a process running from a user-writable folder.
$jsonl = @'
{"host":"ws1.lab.test","time":"2026-01-15T09:12:00Z","event":{"id":4688,"data":{"User":"LAB\\alice","Parent":"C:\\Windows\\explorer.exe","Image":"C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE","CommandLine":"WINWORD.EXE /n invoice.docm"}}}
{"host":"ws1.lab.test","time":"2026-01-15T09:12:09Z","event":{"id":4688,"data":{"User":"LAB\\alice","Parent":"C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE","Image":"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe","CommandLine":"powershell.exe -nop -w hidden -enc VwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIAAnAGgAZQBsAGwAbwAgAGwAYQBiACcA"}}}
{"host":"ws1.lab.test","time":"2026-01-15T09:12:15Z","event":{"id":4688,"data":{"User":"LAB\\alice","Parent":"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe","Image":"C:\\Users\\alice\\AppData\\Local\\Temp\\updater.exe","CommandLine":"updater.exe --lab-marker"}}}
{"host":"ws2.lab.test","time":"2026-01-15T09:30:00Z","event":{"id":4688,"data":{"User":"LAB\\bob","Parent":"C:\\Windows\\explorer.exe","Image":"C:\\Windows\\System32\\notepad.exe","CommandLine":"notepad.exe notes.txt"}}}
{"host":"ws2.lab.test","time":"2026-01-15T09:31:00Z","event":{"id":4688,"data":{"User":"LAB\\bob","Parent":"C:\\Windows\\explorer.exe","Image":"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe","CommandLine":"powershell.exe -File C:\\Scripts\\inventory.ps1"}}}
'@
$events = $jsonl -split "`n" | Where-Object { $_.Trim() } | ForEach-Object { $_ | ConvertFrom-Json } |
Select-Object host,
@{n='Time'; e={ ([datetime]$_.time).ToUniversalTime() }},
@{n='User'; e={ $_.event.data.User }},
@{n='Parent'; e={ Split-Path -Leaf ($_.event.data.Parent -replace '\\', '/') }},
@{n='Image'; e={ $_.event.data.Image }},
@{n='Cmd'; e={ $_.event.data.CommandLine }}
"{0} events from {1} hosts" -f $events.Count, ($events.host | Sort-Object -Unique).Count
$office = 'WINWORD.EXE', 'EXCEL.EXE', 'POWERPNT.EXE', 'OUTLOOK.EXE'
foreach ($e in $events) {
$leaf = Split-Path -Leaf ($e.Image -replace '\\', '/')
if ($office -contains $e.Parent -and $leaf -match '^(powershell|pwsh|cmd|wscript|mshta)\.exe