Skip to content

Instantly share code, notes, and snippets.

@s-h-a-d-o-w
Last active January 31, 2026 15:23
Show Gist options
  • Select an option

  • Save s-h-a-d-o-w/934c6ef2e05f3f3ba74f4f6c0b1bf94f to your computer and use it in GitHub Desktop.

Select an option

Save s-h-a-d-o-w/934c6ef2e05f3f3ba74f4f6c0b1bf94f to your computer and use it in GitHub Desktop.
Repeatedly checks whether a certain IP is reachable and shows a popup if it's not.
$ip = "..."
Add-Type -AssemblyName System.Windows.Forms
$ping = New-Object System.Net.NetworkInformation.Ping
while ($true) {
$failures = 0
for ($i = 0; $i -lt 15; $i++) {
try {
$result = $ping.Send($ip, 3000) # 3 second timeout
if ($result.Status -ne 'Success') { $failures++ }
} catch {
$failures++
}
Start-Sleep -Seconds 1
}
if ($failures -eq 15) { # All 15 failed
[System.Windows.Forms.MessageBox]::Show(
"Device $ip is offline!",
"Network Alert",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Warning
) | Out-Null
}
Start-Sleep -Seconds 5
}
@s-h-a-d-o-w
Copy link
Author

Don't use Test-Connection, it's highly unreliable.

Also, for running this in the background with Task Scheduler, you'll need a second script:

Start-Process pwsh -ArgumentList @(
    "-ExecutionPolicy", "Bypass",
    "-File", "...\offline-check.ps1"
) -WindowStyle Hidden

exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment