-
Notifications
You must be signed in to change notification settings - Fork 1
/
pping.ps1
39 lines (34 loc) · 1.63 KB
/
pping.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Summary: "Smart" ping which alerts you if host comes online or if the host goes down and then comes back online again. Useful for server reboots where you start pinging as soon as server restart command is sent but it stills pings until server is completely offline.
function pping
{
param($hostname)
# If ping-able
if (Test-Connection $hostname -Quiet -Count 1)
{
$sendnotification = 0
# Ping until $hostname can no longer be pinged
Write-Host "$hostname is currently online, waiting until it goes offline..."
do {
$ping = Test-Connection $hostname -Quiet -Count 1
#write-host "host is still online..."
start-sleep -Seconds 1.5
} until (!$ping)
# Wait for $hostname to come back online to notify
Write-Host "$hostname is now offline, waiting for it to come online..."
while (-not (Test-Connection $hostname -Quiet -Count 1))
{
Start-Sleep -Seconds 1.5
#Write-Host "host is no longer online..."
}
Add-Type -AssemblyName Microsoft.VisualBasic
$result = [Microsoft.VisualBasic.Interaction]::MsgBox("$hostname is BACK online!", 'OKOnly,SystemModal,Information', 'PPING')
# Exit script otherwise the while loop below will trigger causing duplicate online message
Return "End of pping"
}
while (-not (Test-Connection $hostname -Quiet -Count 1))
{
Start-Sleep -Seconds 1.5
}
Add-Type -AssemblyName Microsoft.VisualBasic
$result = [Microsoft.VisualBasic.Interaction]::MsgBox("$hostname is online!", 'OKOnly,SystemModal,Information', 'PPING')
}