Use PowerShell to test connection to a port

To quickly test if you can communicate with a server on a specific port use this command:

Test-NetConnection (hostname/ip) -Port (tcp port number)

You are looking for TcpTestSucceeded : True in the output.

Example:

PS C:\Users\Clint> Test-NetConnection www.google.com -port 80

ComputerName : www.google.com
RemoteAddress : 74.125.28.103
RemotePort : 80
InterfaceAlias : vEthernet (LAN) 2
SourceAddress : 192.168.0.5
TcpTestSucceeded : True

This command is quite flexible, you can also have it test with ICMP like PING and Trace Route.

For a simple ping test: Test-NetConnection www.google.com For a trace route test: Test-NetConnection www.google.com -TraceRoute

Does not appear to support UDP test, in PowerShell 5…

Update:

This command doesn’t appear to be in PowerShell Core/PowerShell 6. However, Test-Connection is. It has some different options, I haven’t read all of them, but it appears to be more flexible, however, to get the same result as above run:

Test-Connection www.googgle.com -TCPPort 80

When you check a specific port, it will return a True or False - in my testing it performs this check quickly