Port Testing with PowerShell


It’s been a common practice of mine over the past three decades (yes) to use the Telnet client as a quick and easy way of determining whether a TCP port is open between two computers.  As of Windows Server 2012, Telnet Client is not installed by default, which means you often have to install it to do some basic network connectivity testing.  This is not always possible in some environments, but in some places you might be able to use a lightweight, but powerful, alternative.

Assuming you can execute PowerShell commands – not always a given – you can avoid having to install (and uninstall) Telnet client by using this very helpful PowerShell command.  It’s called:

Test-NetConnection

It’s supported on Windows Server 2012 R2 and 2016, Windows 8.1 and 10.

The general syntax is:  Test-NetConnection -Port 80 -InformationLevel Detailed

Which, by the way, uses a Microsoft edge server as the destination (so it tests outbound on port 80 in this case). 

image

The more useful command would be:

Test-NetConnection –ComputerName (HOST or IP) -InformationLevel Detailed
Which produces the following useful output:
image

What happens if a port is blocked?

image 

image

 

Enjoy.


About Rob Sanders

IT Professional and TOGAF 9 certified architect with nearly two decades of industry experience, 18 years in commercial software development and 11 years in IT consulting. Check out the "About Rob" page for more information.

Leave a comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>