PowerShell Ping Multiple Servers and Export Results

After a network change window, you need to confirm that all 200 servers in your environment are reachable before declaring success. Pinging them manually or in a sequential loop would take 10 minutes; a PowerShell script using parallel pings and exporting results to CSV takes under 30 seconds. This guide shows you how to PowerShell ping multiple servers from a text file list, collect online and offline results, add timestamps, run pings in parallel for speed, and export a structured connectivity report.
Ping from a Text File List
Test-Connection is PowerShell’s built-in equivalent of ping. Using -Quiet returns a simple $true or $false boolean, which is ideal for a connectivity check loop:
$servers = Get-Content "C:\Scripts\servers.txt"
foreach ($server in $servers) {
$online = Test-Connection -ComputerName $server -Count 1 -Quiet
Write-Host "$server : $(if ($online) { 'ONLINE' } else { 'OFFLINE' })"
}
Server01 : ONLINE
Server02 : OFFLINE
Server03 : ONLINE
Collect Online and Offline Results
Build a structured result list rather than printing directly, so you can process, filter, and export the data:
$servers = Get-Content "C:\Scripts\servers.txt"
$results = foreach ($server in $servers) {
$online = Test-Connection -ComputerName $server -Count 1 -Quiet -ErrorAction SilentlyContinue
[PSCustomObject]@{
Server = $server
Online = $online
Status = if ($online) { "Online" } else { "Offline" }
Timestamp = Get-Date
}
}
$online = ($results | Where-Object Online -eq $true).Count
$offline = ($results | Where-Object Online -eq $false).Count
Write-Host "Online: $online | Offline: $offline | Total: $($results.Count)"
Add Timestamp to Results
For scheduled connectivity checks, include the response time alongside the timestamp so you can trend latency over time. Use the full Test-Connection output (without -Quiet) to get response time:
$servers = Get-Content "C:\Scripts\servers.txt"
$results = foreach ($server in $servers) {
$ping = Test-Connection -ComputerName $server -Count 1 -ErrorAction SilentlyContinue
[PSCustomObject]@{
Server = $server
Online = [bool]$ping
ResponseTime = if ($ping) { $ping.ResponseTime } else { $null }
Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
}
}
Parallel Ping for Speed
Sequential pinging becomes slow for large server lists because each ping waits for the timeout before moving to the next offline server. In PowerShell 7, use ForEach-Object -Parallel to ping all servers simultaneously:
#Requires -Version 7.0
$servers = Get-Content "C:\Scripts\servers.txt"
$results = $servers | ForEach-Object -Parallel {
$ping = Test-Connection -ComputerName $_ -Count 1 -ErrorAction SilentlyContinue
[PSCustomObject]@{
Server = $_
Online = [bool]$ping
ResponseTime = if ($ping) { $ping.ResponseTime } else { $null }
Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
}
} -ThrottleLimit 50
$results | Sort-Object Server
For PowerShell 5.1, use background jobs instead (see the jobs pattern with Start-Job / Wait-Job / Receive-Job).
Export Results to CSV
Save the connectivity report to CSV for archiving, sharing with the team, or importing into a ticket:
$reportPath = "C:\Reports\ping-check_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv"
$results | Sort-Object Online, Server | Export-Csv -Path $reportPath -NoTypeInformation
Write-Host "Report saved: $reportPath"
# Show a summary
$results | Group-Object Status | Select-Object Name, Count | Format-Table -AutoSize
Name Count
---- -----
Online 187
Offline 13
Schedule Regular Connectivity Check
Register the script as a scheduled task to run hourly and append results to a running CSV log:
$action = New-ScheduledTaskAction -Execute "pwsh.exe" `
-Argument '-NonInteractive -File "C:\Scripts\Ping-Servers.ps1"'
$trigger = New-ScheduledTaskTrigger -RepetitionInterval (New-TimeSpan -Hours 1) -Once -At (Get-Date)
Register-ScheduledTask -TaskName "HourlyPingCheck" -Action $action -Trigger $trigger `
-RunLevel Highest -Description "Pings all servers hourly and logs results" -Force
Write-Host "Scheduled task registered"
Common Errors and Fixes
-
ICMP blocked on some servers — false offline result. Many Windows servers have ICMP disabled by firewall policy. A server that shows as offline may actually be reachable on TCP ports. For critical hosts, supplement the ping check with a TCP port test:
Test-NetConnection -ComputerName $server -Port 443 -InformationLevel Quiet. -
DNS resolution failure looks like offline — check separately. If a hostname cannot be resolved,
Test-Connectionthrows a non-terminating error and returns nothing (not$false). Wrap the call intry/catchwith-ErrorAction Stop, or resolve DNS first withResolve-DnsNameto distinguish DNS failures from actual offline hosts.
Related Cmdlets / See Also
Wrapping Up
A parallel ping script with CSV export turns a 10-minute manual check into a 30-second automated report. Use ForEach-Object -Parallel in PowerShell 7 for speed, supplement ICMP checks with TCP port tests for hardened servers, and schedule regular runs to build a historical connectivity baseline.


