Use Test-NetConnection in PowerShell to See If A Port Is Open

The days of using ping.exe to see if a host is up or down are over. Your network probably shouldn’t allow ICMP to just fly around unaddressed, and your hosts probably shouldn’t return ICMP echo request (ping) messages either. So how do I know if a host is up or not?

Well, it involves knowing about what your host actually does. What ports are supposed to be open? Once you know that, you can use Test-NetConnection in PowerShell to check if the port is open and responding on the host you’re interested in.

PS> Test-NetConnection -ComputerName $computerName -Port 3389

ComputerName     : <snip - name of the computer I'm testing>
RemoteAddress    : <snip - IP address of the computer I'm testing>
RemotePort       : 3389
InterfaceAlias   : Ethernet
SourceAddress    : <snip - my IP address>
TcpTestSucceeded : True

Here I just checked if port 3389 (for RDP) is open or not. Looks like it is.

Written on July 26, 2017