Skip to content

Instantly share code, notes, and snippets.

@JFFail
Last active August 29, 2015 14:18
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 JFFail/7e90e545a92c742fd55a to your computer and use it in GitHub Desktop.
Save JFFail/7e90e545a92c742fd55a to your computer and use it in GitHub Desktop.
Script to kill psping instances when they crash due to too many connectivity failures.
$failCounter = 0
$phrases = ("Process Kill!", "Double Process!", "Triple Process!", "Processtacular!", "Process Frenzy!", "Proctrocity!", "Procemanjaro!")
while($true)
{
#Query all processes.
$processes = Get-Process
$counter = 0
#Count the psping instances.
foreach ($process in $processes)
{
if($process.ProcessName -eq "psping")
{
$counter++
}
}
#See if we need to kill them.
if($counter -gt 1)
{
#Write output.
Write-Host $phrases[$failCounter] -ForegroundColor Red
#Find and kill the fault process.
$fault = Get-Process -ProcessName werfault
Stop-Process $fault
#Increment the counter.
if($failCounter -lt 6)
{
$failCounter++
}
}
else
{
Write-Host "Nothing to kill yet..."
}
#Sleep for 10 seconds.
Start-Sleep -Seconds 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment