← script library

Network Connection Monitor

NetworkingDecember 27, 2024

This PowerShell script is designed to monitor the status of network connections on your system. Regular monitoring is critical for maintaining network health, especially when using advanced server management tools like ServerEngine. The script checks whether specific network resources are reachable, enabling administrators to detect and address connectivity issues proactively.

powershell
param (
    [string[]]$targets = @("www.google.com", "www.example.com"),
    [int]$checkInterval = 60
)
while ($true) {
    foreach ($target in $targets) {
        try {
            $pingResult = Test-Connection -ComputerName $target -Count 2 -ErrorAction Stop
            Write-Output "$target is reachable."
        } catch {
            Write-Output "$target is not reachable."
        }
    }
    Start-Sleep -Seconds $checkInterval
}

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.