Powershell

Test-Connection: Ping Remote Hosts the PowerShell Way

The cmdlet “Test-Connection” in PowerShell sends ICMP (Internet Control Message Protocol) to echo request pings or packets to one or more remote computers using WMI. In return, it gives the echo response. This cmdlet determines whether a specified computer can be contacted across the IP network or not. More specifically, the stated command is the alternative to Linux’s “ping” cmdlet.

This post will elaborate on the “Test-Connection” cmdlet to ping the remote host.

Test-Connection: Ping Remote Hosts the PowerShell Way

The cmdlet “Test-Connection” in PowerShell is utilized to ping the host or local computer. The core feature of the stated cmdlet is to check whether the host computer can be contacted over the IP network or not. Further explanation of the stated cmdlet is demonstrated in the below examples.

Example 1: Test Connections of Local Computer

The following example will test the connections of the local computer:

Test-Connection -ComputerName DESKTOP-CVNOA2L

 

According to the above-stated command:

  • First, add the “Test-Connection” cmdlet followed by the “-ComputerName” parameter.
  • Assign the local computer name to it:

It can be observed that the local computer connections have been tested successfully.

Example 2: Test Connection of Specified URL

This example will test the URL to check whether it can be connected or not:

Test-Connection google.com

 

Example 3: View Details of the Tested Connection

This illustration will provide detailed information about the provided URL or remote computer:

Test-Connection www.google.com | Select-Object -Property *

 

Here:

  • First, specify the “Test-Connection” cmdlet and assign it the host URL.
  • After that, add the pipeline “|” to transfer the output of the previous command to the next.
  • Then, write the “Select-Object” cmdlet, followed by the “-property” parameter, and place the “*” symbol at the end:

Example 4: Test Connections of a Specific System

This demonstration will test if the specified computer can be connected or not. The output will be provided in the boolean form, which is “True” or “False” based on the connection result:

Test-Connection -ComputerName DESKTOP-CVNOA2L -Quiet -Count 1

 

According to the above code:

  • Firstly, write the “Test-Connection” cmdlet.
  • Then, add the “-ComputerName” parameter and assign the computer name to it.
  • After that, specify the “-Quiet” parameter which will give the output in boolean form.
  • Then, define the “-Count” parameter and assign the value “1” to it:

That was all about pinging single or multiple hosts using PowerShell.

Conclusion

The “Test-Connection” cmdlet in PowerShell is used to ping one or more computers. In return, it gets the echo requests which determine the connectivity of the remote servers. This blog has observed complete details about the usage of the “Test-Connection” cmdlet.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.