Use PowerShell to test connection to a port

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 -port 80

ComputerName : RemoteAddress : RemotePort : 80 InterfaceAlias : vEthernet (LAN) 2 SourceAddress : 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 For a trace route test: Test-NetConnection -TraceRoute

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


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 -TCPPort 80

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

comments powered by Disqus