Skip to content

Instantly share code, notes, and snippets.

@bill-long
Last active January 8, 2021 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/ff47e24a04dda89a8ab18e4561dc34a2 to your computer and use it in GitHub Desktop.
Save bill-long/ff47e24a04dda89a8ab18e4561dc34a2 to your computer and use it in GitHub Desktop.
# Dump-ScanningProcessOnTimeout
###################################
#
# Change these paths as needed.
#
$dumpFolder = 'C:\data'
$procdumpBinary = 'C:\ProgramData\chocolatey\lib\sysinternals\tools\procdump.exe'
#
###################################
$serverName = [Environment]::MachineName
$startTime = (Get-Date).ToString("o")
"Watching for events. Ctrl-C to exit."
$dumpsGenerated = $false
while ($true)
{
$newEvents = Get-WinEvent -ComputerName $serverName -FilterHashTable @{LogName="Application";StartTime=$startTime;ID=2213} -ErrorAction SilentlyContinue
if ($newEvents -eq $null)
{
Start-Sleep -Milliseconds 250
continue
}
foreach ($event in $newEvents)
{
$m = $event.Message | Select-String "PID=(\d+)"
$p = $m.Matches.Groups[1].Value
Write-Host "Timeout detected on scanningprocess PID $p"
Write-Host "Dumping PID $p"
& $procdumpBinary -ma $p $dumpFolder -accepteula
$dumpsGenerated = $true
}
if ($dumpsGenerated)
{
"Dumps were generated. Pausing for 1 minute..."
Start-Sleep 60
$dumpsGenerated = $false
}
$startTime = (Get-Date).ToString("o")
"Watching for events. Ctrl-C to exit."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment