Last active
August 29, 2015 14:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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