← script library

Network Connection Status Checker Script

NetworkingJanuary 14, 2025

This PowerShell script checks the status of network connections on your machine. By providing detailed information about active network interfaces, this script can help system administrators in monitoring network health, troubleshooting connectivity issues, and managing network resources more efficiently.

powershell
$networkAdapters = Get-NetAdapter | Where-Object { $_.Status -eq 'Up' }

foreach ($adapter in $networkAdapters) {
    $adapterInfo = @{
        'Name'               = $adapter.Name
        'InterfaceDescription' = $adapter.InterfaceDescription
        'LinkSpeed(Mbps)'    = [math]::round($adapter.LinkSpeed / 1MB, 2)
    }
    $adapterInfo
}

foreach ($adapter in $networkAdapters) {
    $ipConfig = Get-NetIPAddress -InterfaceAlias $adapter.Name | Select-Object IPAddress, PrefixLength
    $ipConfig | ForEach-Object {
        Write-Host "Adapter: $($adapter.Name) - IP Address: $($_.IPAddress) - Subnet Mask: $($_.PrefixLength)"
    }
}

foreach ($adapter in $networkAdapters) {
    $pingResult = Test-Connection -ComputerName "google.com" -Count 2 -ErrorAction SilentlyContinue
    if ($pingResult) {
        Write-Host "Adapter: $($adapter.Name) - Connectivity: Online"
    } else {
        Write-Host "Adapter: $($adapter.Name) - Connectivity: Offline"
    }
}

Write-Host "Network Connection Status Report:"
foreach ($adapter in $networkAdapters) {
    Write-Host "--------------------------------"
    Write-Host "Adapter: $($adapter.Name)"
    Write-Host "Status: Up"
    $ipConfig = Get-NetIPAddress -InterfaceAlias $adapter.Name | Select-Object IPAddress, PrefixLength
    foreach ($ip in $ipConfig) {
        Write-Host "IP Address: $($ip.IPAddress) | Subnet Mask: $($ip.PrefixLength)"
    }
    $pingResult = Test-Connection -ComputerName "google.com" -Count 1 -ErrorAction SilentlyContinue
    Write-Host "Connectivity: $(if ($pingResult) { 'Online' } else { 'Offline' })"
}

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.