PowerShell Genie

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.

Command 4 min read PowerShell 7 on Windows

Documentation: Microsoft Learn — test-connection

Syntax

1PS> Test-Connection [-ComputerName] <String[]> [-Count <Int32>] [-Delay <Int32>] [-BufferSize <Int32>] [-Quiet] [-Detailed] [<CommonParameters>]
2PS> Test-Connection [-TargetName] <String[]> -TcpPort <Int32> [-Count <Int32>] [-TimeoutSeconds <Int32>] [-Quiet] [<CommonParameters>]

Try it

Windows PowerShell

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.

Interactive simulation · fictional data

Examples

Ping a host four times

1PS> Test-Connection -ComputerName 8.8.8.8 -Count 4
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

1PS> Test-Connection -TargetName dbserver01 -TcpPort 1433
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

1PS> Test-Connection -ComputerName fileserver01 -Count 1 -Quiet
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.

Microsoft Learn — test-connection

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
Genie guideTest-Connection

Test-Connection is PowerShell's ping command: check whether a host answers, measure round-trip time, test a TCP port, and use -Quiet for a script-friendly true or false result. The console below is pre-loaded — run it, then change a value and run it again.