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.
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, IPv4Address, 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
If you need to send ICMP echo requests continuously (similar to ping -t), PowerShell 7 provides 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+. Windows PowerShell 5.1 doesn’t support continuous ping mode through the Test-Connection cmdlet.
In PowerShell 7.x, you can use the -MtuSize attribute to get the path MTU size:
Test-Connection -TargetName theitbros.com -MtuSize

Important. Note that Test-Connection has evolved significantly between Windows PowerShell 5.1 and modern PowerShell. Some parameter names and behaviors differ between versions. For example, PowerShell 7 supports the -Source parameter for specifying the source computer or IP address, while newer parameters such as -Traceroute, -MtuSize, and -TimeoutSeconds are available in modern PowerShell versions.
In modern PowerShell, -Source can be used to specify the source computer or IP address from which the ICMP request should be sent:
Test-Connection -Source 192.168.1.10 -TargetName 8.8.8.8
Run Test-Connection as a Background Job
In Windows PowerShell 5.1, you can run Test-Connection as a background job:
$pingjob = Start-Job -ScriptBlock {
Test-Connection -ComputerName (Get-Content "C:\PS\CheckServers.txt")
}
$Results = Receive-Job $pingjob -Wait For PowerShell 7, you should prefer parallel execution:
$Servers = Get-Content "C:\PS\CheckServers.txt"
$Servers | ForEach-Object -Parallel {
Test-Connection -TargetName $_ -Count 1
} -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.
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.
To display only reachable servers, use the command:
$Servers |
Where-Object {
Test-Connection -TargetName $_ -Count 1 -Quiet
}
In order to identify unreachable hosts, use the command:
$Servers |
Where-Object {
-not (Test-Connection -TargetName $_ -Count 1 -Quiet)
}
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 |
Export-Csv .\ping.csv -NoTypeInformation
In order to check multiple servers and export only the availability status, run the command:
$Servers = Get-Content .\servers.txt
$Servers |
ForEach-Object {
[PSCustomObject]@{
Server = $_
Reachable = Test-Connection -TargetName $_ -Count 1 -Quiet
}
} |
Export-Csv .\results.csv -NoTypeInformation
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 the -Traceroute option (available in PowerShell Core 6.x+), you can trace a 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:
$Results = Test-Connection `
-TargetName server01 `
-Count 20 `
-ErrorAction SilentlyContinue
$Sent = 20
$Received = $Results.Count
$Lost = $Sent - $Received
$LossPercent = [math]::Round(($Lost / $Sent) * 100, 2)
[PSCustomObject]@{
Sent = $Sent
Received = $Received
Lost = $Lost
LossPercent = $LossPercent
}
Here is an example of the output:
Sent : 20
Received : 18
Lost : 2
LossPercent : 10
This method is useful when you are troubleshooting unstable network connections, intermittent packet loss, VPN links, wireless networks, or WAN connectivity issues.
Ping from Remote Computers
In order to test connectivity from remote computers, run Test-Connection remotely with PowerShell Remoting:
Invoke-Command `
-ComputerName "lon-app1","par-man01","tw-man02" `
-ScriptBlock {
Test-Connection -TargetName theitbros.com -Count 2
}
This command runs Test-Connection on each remote machine and returns the results to the local PowerShell session.
Note. Keep in mind that PowerShell 7 uses the -TargetName parameter for specifying destination hosts. Legacy examples for Windows PowerShell 5.1 may use -ComputerName instead.
ICMP and TCP Connectivity Testing with Test-NetConnection
The Test-NetConnection cmdlet is primarily used for network connectivity diagnostics (including TCP port testing, route information, and ICMP connectivity checks). If the remote host responds to ICMP echo requests, the output includes:
PingSucceeded : True
PingReplyDetails (RTT) : 96 ms

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.
Testing TCP Ports with Test-Connection
In PowerShell 7 and later, Test-Connection can also test TCP ports using the -TcpPort parameter:
Test-Connection -TargetName server01 -TcpPort 443
For example, to test RDP, use the following command:
Test-Connection -TargetName server01 -TcpPort 3389
This provides you with a convenient alternative to Test-NetConnection when you want to use the same cmdlet for both ICMP and TCP connectivity tests. For more detailed network diagnostics, including route info and TCP connection details, Test-NetConnection remains useful.
Quiet Mode for Scripting
When you only need to determine whether a host is reachable, you should use the -Quiet parameter. Instead of returning detailed ping statistics, the cmdlet returns a Boolean value:
Test-Connection -TargetName server01 -Quiet
The possible results are True or False.
This option is especially useful in PowerShell scripts and conditional statements:
if (Test-Connection -TargetName server01 -Quiet)
{
Write-Host "Server is online"
}
else
{
Write-Host "Server is unreachable"
}
You can also specify the number of echo requests to send using the command:
Test-Connection -TargetName server01 -Count 2 -Quiet
Testing availability of remote computers using ICMP Ping
Testing the availability of remote computers using ICMP Ping is useful in PowerShell scripts if you need to perform some action. For example, you run PowerShell script on remote computer only if one of the pings sent to the computer succeeds:
$servername="tw-man02"
if (Test-Connection -TargetName $servername -Count 1 -Quiet)
{
Invoke-Command -ComputerName $servername -ScriptBlock { Restart-Service spooler }
}
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.
