Skip to content

Instantly share code, notes, and snippets.

@mySYSMON
Last active December 12, 2020 01:04
Show Gist options
  • Save mySYSMON/2339cf034c057f6211cb44581148c4ea to your computer and use it in GitHub Desktop.
Save mySYSMON/2339cf034c057f6211cb44581148c4ea to your computer and use it in GitHub Desktop.
sysmon1-stats-count-by-image.ps1
$events = Get-WinEvent -FilterHashtable `
@{ `
logname='Microsoft-Windows-Sysmon/Operational'; `
id=1; `
StartTime=(Get-Date).AddHours(-1); `
EndTime=get-date `
}
$dict = @{}
foreach ($log in $events)
{
[xml]$xmllog = $log.toXml()
$tmp = $xmllog.event.eventdata.data | where Name -eq 'image' | select '#text'
$image = $tmp.'#text'
$value = $dict[$image]
if ($value -eq $null)
{
$value = 1
$dict.add($image,$value)
}
else
{
$value = $value + 1
$dict[$tmp] = $value
}
}
$dict.GetEnumerator() | sort -Property value -Descending
# RUN LIKE THIS
# sysmon1-stats-count-by-image.ps1 | format-list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment