Skip to content

Instantly share code, notes, and snippets.

@martin9700
Created January 12, 2014 21:28
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 martin9700/8390806 to your computer and use it in GitHub Desktop.
Save martin9700/8390806 to your computer and use it in GitHub Desktop.
$Back = @()
ForEach ($Result in $Results)
{ $Key = "$($Result.PSComputerName):$($Result.Address)"
$Status[$Key].'IP Address' = $Result.IPV4Address
If ($Result.StatusCode -eq 0)
{ If ($Status[$Key].'Failed Pings' -ge 3)
{ $Back += [PSCustomObject]@{
Destination = $Result.Address
From = $Result.PSComputerName
IPAddress = $Result.IPV4Address
Status = "Connectivity Returned"
}
}
$Status[$Key].'Failed Pings' = 0
}
Else
{ $Status[$Key].'Failed Pings' ++
}
}
If ($Back)
{ $HTML = $Back | Sort Destination,From | ConvertTo-Html -Head $Header -PreContent "<p>Ping Detection Script has detected <i>restored</i> connections!<br></p>" | Out-String
Send-MailMessage -To $To -From $From -Subject "Connections Restored" -Body $HTML -BodyAsHtml -SmtpServer $SMTPServer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment