Test-NetConnection to check if specific port is open in windows

There are many ways to check whether the specific port is open in our computer, today here I’m going to share the powershell way on how to check if specific port is open in windows.

Test-NetConnection Powershell cmdlet:

Test-NetConnection is the new cmdlet introduced by microsoft in powershell 4.0 version i.e from windows 8 and windows server 2012 operating system this cmdlet is used to check network connectivity like ping, traceroute and port check.

Get-Help Test-NetConnection

The above command will provide us the syntax and usage of Test-NetConnection.

Test-NetConnection -ComputerName Google.com

From the above command we just tried to query the connectivity to google.com, if output returns status as true means the connection is getting succeeded, whereas if connectivity fails then the output returns status as false.

Test-NetConnection -ComputerName Google.com -Port 80

Here from the above command we are testing whether the specific port 443 is open on the computer named google.com (just for testing) you should use the remote computer name that you’re trying to query in this field, if the output returns status as true then the specific port is open on the computer, whereas if output returns the status as false then the specified port is not open in particular computer.

Test-NetConnection -ComputerName Google.com -CommonTCPPort HTTP

We can even check the port open details by name i.e using CommonTCPPort parameter as listed in the above screenshots but it only supports the following HTTP,RDP,SMB,WINRM for rest of ports we need to use Port parameter followed by port number as listed in previous example.

Test-NetConnection -ComputerName Google.com -Port 443 -InformationLevel Detailed

This command supports parameter called InformationLevel where it provides few more details for the query we execute, refer to the above screenshot that shows few more details while we tried to query google.com using port 443 with and without InformationLevel parameter.

Hope this article helps to solves your query on how to check if specific port is open in windows, execute this script at your own risk as we do not provide any guarantee or warranty.