PowerShell Script Test Open TCP Ports

1 minute read

Recently I was troubleshooting ADFS connection issues when I discovered a nice little Cmdlet called “Test-NetConnection”. With this Cmdelet you can verify TCP connectivity, in my case from a client to the ADFS server.

The Test-NetConnection cmdlet displays diagnostic information for a connection. It supports ping test, TCP test, route tracing, and route selection diagnostics. Depending on the input parameters, the output can include the DNS lookup results, a list of IP interfaces, IPsec rules, route/source address selection results, and/or confirmation of connection establishment.

Find a full documentation on the Microsoft Docs Page.

About the script

With this Script you are able to specify server names and port numbers to check in a CSV File. The Script generates an CSV output file as a report. You can use this script for troubleshooting or engineering purposes to verify if TCP ports are opened.

Simply add the hostname and TCP port to the “CheckList.csv” and the script checks the specified servers and ports.

The script will generate an output file for the same path containing the suffix “Report_” with the test results.

  • CheckList.csv:

  • Report_CheckList.csv generated after script execution: Report_CheckList.csv

Executing the script

To execute the script simply add the “-Path” parameter to specifiy the path to the CheckList.csv template.

PS C:\techblog> &"Check-Ports.ps1" -Path "CheckList.csv"


PowerShell Script Test Open TCP Ports

Download the CSV template