Created
May 26, 2011 06:02
-
-
Save jonsagara/992625 to your computer and use it in GitHub Desktop.
Pinger - Repeatedly pings the specified server until the ping is successful.
This file contains 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
# ------------------------------------------------------------------------------------------------- | |
# Pinger.ps1 | |
# | |
# Repeatedly pings the specified server until the ping is successful. | |
# ------------------------------------------------------------------------------------------------- | |
# Script params | |
param([String]$server) | |
# Script param validation | |
if ([String]::IsNullOrEmpty($server)) { | |
throw "You must specify a `$server to ping" | |
} | |
$pingOutput = @() | |
while ($pingOutput.Length -eq 0) { | |
Write-Host "Pinging $server..." | |
$pingOutput = @((ping $server -n 2) | where { $_ -match "TTL=[\d]{1,}" }) | |
} | |
Write-Host "$server pinged successfully." | |
# Send an email notifying that the server is back online | |
$smtpClient = New-Object Net.Mail.SmtpClient | |
$smtpClient.Host = "smtp.example.com" | |
$currentUser = $env:UserName | |
$from = "[email protected]" | |
$to = "[email protected]" | |
$title = "$server was pinged successfully, and appears to be back up" | |
$body = "$server was pinged successfully, and appears to be back up" | |
$smtpClient.Send($from, $to, $title, $body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment