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:
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:
Example 3: View Details of the Tested Connection
This illustration will provide detailed information about the provided URL or remote computer:
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:
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.