A powerful Test-Connection PowerShell cmdlet is available as a replacement for the ping command in Windows. The Test-Connection command allows you to send ICMP echo requests packets to one or more remote hosts and receive echo response replies.
Note that our article uses PowerShell 7.6 LTS, released in March 2026. Some features and parameters may not be available in Windows PowerShell 5.1. In case you`re working in an enterprise environment, verify the installed PowerShell version before running the examples.
Using Test-Connection
To check the availability of a remote host via ping ICMP, run the command:
Test-Connection -TargetName theitbros.com

Note. A failed ping test does not always mean that the remote host is offline. Many systems block ICMP traffic by firewall/security policy. When troubleshooting connectivity, you should check the required application port with Test-NetConnection.
You can use pipe with the Select-Object cmdlet to select only the required properties in the command results:
Test-Connection -TargetName theitbros.com |
Select-Object Address, Latency
You can save the results of a ping test to a PowerShell variable and access individual properties later in your script using the command:
$Result = Test-Connection -TargetName server01 -Count 1
For example, you can display the ping status and latency with the following commands:
$Result.Status
$Result.Latency
This method is useful in PowerShell automation, reporting scripts, and custom monitoring solutions where you need to process ping results programmatically.
List all possible attributes with the command:
Test-Connection -TargetName theitbros.com -Count 1 | Get-Member
By default, the cmdlet sends 4 ICMP packets. You can perform a ping check with a single packet:
Test-Connection -TargetName theitbros.com -Count 1
You can change the delay (in seconds) between sending packets and the buffer size (in bytes):
Test-Connection -TargetName theitbros.com -Delay 4 -BufferSize 128
With PowerShell, you can send ICMP echo requests continuously with the -Repeat parameter:
Test-Connection -TargetName 1.1.1.1 -Repeat
For Windows PowerShell 5.1, you can use a simple loop:
while ($true)
{
Test-Connection -ComputerName 1.1.1.1 -Count 1
Start-Sleep -Seconds 1
}
Alternatively, you can use the classic command:
ping -t 1.1.1.1
Note. The -Repeat parameter is available in PowerShell 7.6 LTS and other supported versions that include this parameter. Windows PowerShell 5.1 does not support continuous ping mode through the Test-Connection cmdlet, so you can use a loop or the native ping -t command instead.
In PowerShell 7.x, you can use the -MtuSize parameter to get the path MTU size:
Test-Connection -TargetName theitbros.com -MtuSize

For the complete syntax and parameter reference for Test-Connection cmdlet, see the Microsoft Learn documentation.
Run Test-Connection in Parallel
In Windows PowerShell 5.1, Test-Connection supports the -AsJob parameter for running ping tests as a background job:
$Servers = Get-Content "C:\PS\CheckServers.txt"
$PingJob = Test-Connection -ComputerName $Servers -Count 1 -AsJob
$Results = Receive-Job -Job $PingJob -Wait
Remove-Job -Job $PingJob
In PowerShell 7 and later, use ForEach-Object -Parallel to run ping tests concurrently:
$Servers = Get-Content .\servers.txt
$Servers | ForEach-Object -Parallel {
Test-Connection `
-TargetName $_ `
-Count 1 `
-TimeoutSeconds 2
} -ThrottleLimit 20
The -ThrottleLimit parameter limits the number of parallel tasks running simultaneously. This helps you to prevent excessive CPU and memory usage when testing connectivity to large numbers of servers.
Note. The $_ automatic variable represents the current pipeline input and is available inside the parallel script block. In order to access variables from the parent scope, you should use the $using: scope modifier. For example, $using:Timeout passes an external timeout value into the parallel script block.
Test Multiple Servers at Once
You can use Test-Connection to check the availability of multiple servers in a single command. In case you have a list of server names stored in a text file, use the following:
$Servers = Get-Content .\servers.txt
Test-Connection `
-TargetName $Servers `
-Count 1
The command sends one ICMP echo request to each server and returns the results.
You should use -Quiet when you only need a Boolean result ($true or $false) instead of the full ping response.
To display only reachable servers, use the command:
$Servers | ForEach-Object -Parallel {
if (Test-Connection `
-TargetName $_ `
-Count 1 `
-TimeoutSeconds 2 `
-Quiet `
-ErrorAction SilentlyContinue) {
$_
}
} -ThrottleLimit 20 In order to identify unreachable hosts, use the command:
$Servers | ForEach-Object -Parallel {
if (-not (Test-Connection `
-TargetName $_ `
-Count 1 `
-TimeoutSeconds 2 `
-Quiet `
-ErrorAction SilentlyContinue)) {
$_
}
} -ThrottleLimit 20 Export Ping Results to CSV
You can export ping test results to a CSV file for reporting or further analysis. For a single host, use the following command:
Test-Connection -TargetName server01 -Count 1 |
Select-Object Address, Latency, Status |
Export-Csv .\ping.csv
In order to check multiple servers and export only the availability status, run the command:
$Servers = Get-Content .\servers.txt
$Servers |
ForEach-Object -Parallel {
[PSCustomObject]@{
Server = $_
Reachable = Test-Connection `
-TargetName $_ `
-Count 1 `
-TimeoutSeconds 2 `
-Quiet `
-ErrorAction SilentlyContinue
}
} -ThrottleLimit 20 |
Export-Csv .\results.csv
You can open the resulting CSV file in Microsoft Excel or you can import it into other reporting tools.
Trace path to remote host
With PowerShell, you can use the -Traceroute parameter to trace the network path to a remote host:
Test-Connection -TargetName theitbros.com -Traceroute
Analyzing Packet Loss
In network troubleshooting, packet loss is often more important than a simple online/offline check. You can send multiple ICMP requests and calculate how many replies were successfully received.
The following example sends 20 echo requests and calculates the packet loss percentage:
$Target = "server01"
$Sent = 20
$TimeoutSeconds = 2
$Results = Test-Connection `
-TargetName $Target `
-Count $Sent `
-TimeoutSeconds $TimeoutSeconds `
-ErrorAction SilentlyContinue
$Received = @($Results | Where-Object Status -eq 'Success').Count
$Lost = $Sent - $Received
$LossPercent = [math]::Round(($Lost / $Sent) * 100, 2)
[PSCustomObject]@{
Target = $Target
Sent = $Sent
Received = $Received
Lost = $Lost
LossPercent = $LossPercent
}
Here is an example of the output:
Target : server01
Sent : 20
Received : 18
Lost : 2
LossPercent : 10
This is a basic ICMP loss calculation and you should not treat it as a complete network performance test. ICMP may be rate-limited/deprioritized, so correlate the results with TCP/application-level tests and network monitoring.
Ping from Remote Computers
By default, PowerShell Remoting to Windows hosts uses the Windows PowerShell 5.1 remoting endpoint. In order to run Test-Connection with the PowerShell 7 syntax shown in our article, the PowerShell 7 remoting endpoint must be installed and configured on the target machines. The PowerShell.7 session config must be available on each remote host.
To test connectivity from remote machines, run Test-Connection remotely with PowerShell Remoting:
Invoke-Command `
-ComputerName "lon-app1","par-man01","tw-man02" `
-ConfigurationName PowerShell.7 `
-ScriptBlock {
Test-Connection -TargetName theitbros.com -Count 2
}
This command runs Test-Connection in a PowerShell 7 remoting session on each remote machine and returns the results to the local session.
If the remote machines do not have the PowerShell 7 remoting endpoint configured, you can use the Windows PowerShell 5.1 syntax with -ComputerName instead:
Invoke-Command `
-ComputerName "lon-app1","par-man01","tw-man02" `
-ScriptBlock {
Test-Connection -ComputerName theitbros.com -Count 2
}
ICMP and TCP Connectivity Testing with Test-NetConnection
The Test-NetConnection cmdlet is primarily used for network connectivity diagnostics (including TCP port testing, route info, and ICMP connectivity checks). If the remote host responds to ICMP echo requests, the output includes:
PingSucceeded : True
PingReplyDetails (RTT) : 96 ms

Windows only. Note that Test-NetConnection is provided by the Windows NetTCPIP module and isn’t available on Linux/macOS. In PowerShell 7 on Linux or macOS, you can use the cross-platform Test-Connection -TcpPort parameter for basic TCP connectivity tests. For more advanced platform-specific diagnostics, you can also use native tools such as nc.
Testing TCP Ports with Test-Connection in PowerShell 7
On Windows, Test-NetConnection is generally preferred for TCP and network diagnostics because it provides additional diagnostic info. On Linux and macOS, you should use Test-Connection -TcpPort or platform-native tools such as nc.
Test-Connection -TargetName server01 -TcpPort 443
For example, to test RDP, use the following command:
Test-Connection -TargetName server01 -TcpPort 3389
Test-NetConnection provides additional network info and is generally the better choice for TCP-specific diagnostics.
Testing PowerShell Remoting Availability
If your goal is to run a PowerShell command on a remote Windows machine, you need to test PowerShell Remoting availability instead of using ICMP ping. The Test-WSMan cmdlet checks if the WinRM service is responding on the remote machine:
$ServerName = "tw-man02"
if (Test-WSMan -ComputerName $ServerName -ErrorAction SilentlyContinue) {
Invoke-Command -ComputerName $ServerName -ScriptBlock {
Get-Service Spooler
}
}
See the Microsoft Learn documentation for Test-WSMan for the available parameters and remoting diagnostics.
Testing TCP Ports with Test-NetConnection
While Test-Connection is useful for ICMP ping tests, you may need to check if a specific TCP port is reachable on a remote host. For example, to check HTTPS connectivity, run the command:
Test-NetConnection -ComputerName server01 -Port 443
In order to check Remote Desktop availability, run the following command:
Test-NetConnection server01 -Port 3389
To check SMB file sharing, run the command:
Test-NetConnection server01 -Port 445
The output includes the TcpTestSucceeded property:
TcpTestSucceeded : True
Note that if the connection cannot be established, the result will be:
TcpTestSucceeded : False
If you only need a Boolean result for scripting and monitoring purposes, you should use the -InformationLevel Quiet parameter:
Test-NetConnection server01 -Port 443 -InformationLevel Quiet
Output for the command above is True or False.
What is the difference between Test-Connection and Test-NetConnection?
- Test-Connection tests ICMP connectivity (ping).
- Test-NetConnection tests network connectivity, TCP ports, routing information, and optionally ICMP.
Use Test-NetConnection when you need to verify whether a specific service port is reachable.
Does a failed ping always mean the host is offline?
No. Many servers, firewalls, and cloud services block ICMP traffic for security reasons. If a ping fails, you should verify connectivity using the required application port with Test-NetConnection rather than assuming the host is unavailable.
What’s different about Test-Connection in PowerShell 7?
PowerShell 7 introduced several changes:
- Uses the Latency property instead of RoundTripTime.
- Supports newer parameters such as -Traceroute and -MtuSize.
- Removes some legacy parameters, including -Source.
- Returns PingStatus objects instead of Win32_PingStatus objects.
What is the PowerShell equivalent of the ping command?
PowerShell provides the Test-Connection cmdlet, which sends ICMP echo requests to remote hosts and returns detailed connectivity information.
