microsoft toolkit download

PowerShell Test-Connection Command Tutorial

Windows PowerShell provides the Test-Connection command in order to send packets to the remote systems. Generally, the ICMP packets are used which are also used by the ping command. Simply we can call the Test-Connection as the ping command in order to check remote system accessibility.

Ping Remote IP Address 

We can use the Test-Connection command in order to ping the remote IP addresses. Simply check the connectivity to the network or internet. The Test-Connection can be used for internal networks or public internet. We can specify the remote IP address to ping.

PS> Test-Connection  8.8.8.8

Ping Remote Host with Domain Name

Alternatively, we can specify the remote system with its hostname or domain name. The remote system we want to ping can be specified by using the -TargetName option In the following example we ping the remote system srv1.windowstect.com .

PS> Test-Connection -TargetName srv1.windowstect.com

Ping Multiple Remote Systems

We can execute the Test-Connection command just one time in order to ping multiple remote systems. The remote systems’ IP addresses are provided by separating them into commas.

PS> Test-Connection 8.8.8.8 2.2.2.2 192.168.1.10

Ping IPv6 Address

The most popular version of the IP address is IPv4. But the Test-Connection command can be also used to ping IPv6 addresses for the remote systems.

PS> Test-Connection 2001:0db8:85a3:0000:0000:8a2e:0370:7334

Specify Ping(ICMP) Packet Count 

The Test-Connection command sends ICMP packets to the remote systems. By default, 4 packets are transmitted to the remote systems. But we can change the default packet count with the -Count parameter. In the following example, we sent 10 packets to the remote system.

PS> Test-Connection -Count 10  8.8.8.8

Traceroute To Remote Host 

The Test-Connection command also provides the ability to traceroute to the remote system. The traceroute simply checks every hop to the remote system. The -Traceroute option is specified to enable traceroute information. The trace route information provides the hop number, hostname, latency, status, etc. The traceroute feature is introduced with the PowerShell 6.0 .

PS> Test-Connection -Traceroute  8.8.8.8

Specify Delay/Interval Between Ping Packets

By default, ICMP or ping packets are transmitted at 1-second intervals. But we can also set the delay between packets by using the -Delay . In the following example, we set the delay between packets as 4 seconds.

PS> Test-Connection -Delay 4  8.8.8.8

Specify Max Hops (Intermediate) Hosts

While sending ping packets the intermediate hosts are used to transmit packets to the remote system. There is a limit named MaxHops to prevent loops. The default limit for the Max Hops is 128 for the Windows operating system. But we can set a custom limit by using the -MaxHops option. In the following example, we set the maximum hops as 10.

PS> Test-Connection -MaxHops 10  8.8.8.8

Ping TCP Port Number

The Test-Connection command uses the ICMP packets by default to check remote systems. It also provides the ability to ping remote TCP ports by specifying the TCP port numbers. The -TcpPort option is used to specify the remote system port number to ping and check if the remote port is open and accepts connections. In the following example, we check the HTTP port number 80 whether it is open or closed.

PS> Test-Connection -TcpPort 80  8.8.8.8

Leave a Comment