A remote connection can be tested or pinged using the old-school utility “ping.exe”. However, PowerShell has introduced a couple of “Test-Connection” commands to test a remote connection. This cmdlet pings one or more computers and, in return, gets the echo response. Moreover, this command determines whether a specific computer connected across an IP network can be tested or contacted.
This blog will cover a guide to fix the mentioned query.
How to Use PowerShell to Test a Remote Connection?
These approaches can be applied to test a remote connection:
Method 1: Use the “Test-Connection” Cmdlet to Test a Remote Connection
The “Test-Connection” cmdlet sends echo requests of ICMP (Internet Control Message Protocol) or ping local or remote computers.
Example 1: Executing Simple “Test-Connection” Command
In order to test the remote connection, execute the “Test-Connection” cmdlet:
In the above code, first, add the “Test-Connection” cmdlet and then specify the URL of the remote connection:
Example 2: Executing “Test-Connection” Command With “-Quiet” Option
This example will test a remote connection and will return the boolean value:
In the above-stated code:
- First, add the “Test-Connection” cmdlet and then add the URL of the remote connection.
- After that, specify the “-Quiet” parameter at the end, which will return the output value in a boolean value, “True” or “False”:
Method 2: Use the “Test-NetConnection” Cmdlet to Test a Remote Connection
Another cmdlet used to test the remote connection is the “Test-NetConnection”. It is similar to the “Test-Connection” cmdlet. More or less, it produces the same results as the “Test-Connection” cmdlet, but it is network-oriented.
Example
This example will test a remote connection using the “Test-NetConnection” cmdlet:
Example: Check if a Port is Open
This example will use the “Test-NetConnection” cmdlet to check whether a certain port is open or not:
In the above code:
- First, add the “Test-NetConnection” cmdlet then specify the URL of the remote connection to test.
- After that, add the “-port” parameter and assign the “80” port number to it:
That was all about testing remote connections in PowerShell.
Conclusion
The remote connection can be tested using the “Test-Connection” and the “Test-NetConnection” cmdlets. The former cmdlet tests remote connections with minimal parameters, while the latter is a more network-centered cmdlet and can also check whether the port is open. This blog has presented a detailed procedure to test a remote connection in PowerShell.