How can I test a range of ports for network connectivity in PowerShell?

Problem:

How can I test a range of ports for network connectivity in PowerShell?

Solution:

foreach ($port in 1..1024) {If (($a=Test-NetConnection srvfs01 -Port $port -WarningAction SilentlyContinue).tcpTestSucceeded -eq $true){ "TCP port $port is open!"}}

One Reply to “How can I test a range of ports for network connectivity in PowerShell?”

Leave a Reply

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