Test-Connection
Use Test-Connection to send ICMP ping requests to a computer, test a TCP port, and get a simple true-or-false answer for scripts.
Documentation: Microsoft Learn — test-connection
Syntax
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Examples
Ping a host four times
Show reference output
Illustrative output · values vary by environment
DestinationAddress : 8.8.8.8 PingSucceeded : True RoundTripTime : 12 ms SourceAddress : 192.168.1.10
Test whether a TCP port answers
Show reference output
Illustrative output · values vary by environment
DestinationAddress : dbserver01 TcpPort : 1433 TcpTestSucceeded : True PingSucceeded : False
Get a true-or-false answer for a script
Show reference output
Illustrative output · values vary by environment
True
Parameters
Parameter definitions:
-ComputerName / -TargetName— The host to test. Accepts a name or IP address, and an array of hosts.-Count— How many ping requests to send. Default is 4.-TcpPort— Switches from ICMP ping to a TCP connection test on this port.-Quiet— Returns only True or False instead of detailed objects. Ideal for if statements.-TimeoutSeconds— How long to wait for each reply before giving up.-Detailed— Adds extra output fields such as the resolved address and route information.
Ping is not proof the service is healthy
PingSucceeded only proves the host answers ICMP. Many servers block ping while their services run fine, and a host can answer ping while its application is down. When you care about a service, test its TCP port with -TcpPort instead of relying on ping alone.
In Windows PowerShell 5.1, Test-Connection returns Win32_PingStatus objects with different property names. In PowerShell 7 it returns PingReply-style objects and gains -TcpPort. Check Get-Help Test-Connection on your version before copying a script across versions.
For a quiet check inside a script, combine -Count 1 -Quiet with an if statement. One ping keeps the check fast, and the Boolean result needs no parsing.
Test ports and routes with Test-NetConnection
Check name resolution with Resolve-DnsName
Updated 25 October 2026. Browser outputs are fictional; check the installed module help for your environment.
Recap
Test-Connection Use Test-Connection to send ICMP ping requests to a computer, test a TCP port, and get a simple true-or-false answer for scripts.
Next: Get Credential