A Quick Tip To Check If A Port Is Listening On Multiple Computers

On local computer you can always run NetStat -an command to get the list of all the ports listening on the computer. There is no support available natively on Windows Computers or there is no command line tool available to check if a specific port is listening on multiple computers or not. Let's assume we want to check if 3389 port is listening or not on the servers mentioned in the Servers.txt file. To accomplish this, you need to use the script mentioned below:


  • 1. Create a text file: Servers.txt
  • 2. Put all the Server Names in it.
  • 3. Next, copy the following lines in a file and save it save it as CheckPort.CMD
  • REM ***START HERE***
  • Echo Off
  • SetLocal EnableDelayedExpansion
  • IF EXIST Result.csv DEL Result.csv
  • FOR /F "Tokens=*" %%L IN (Servers.txt) DO (
  •    SET ServerName=
  •    SET ServerName=%%L
  •    Psexec.exe \\!ServerName! NetStat -an > Result.txt
  •    Find /i "3389" < Result.txt
  •    IF !ErrorLevel! == 0 (
  •        Echo !ServerName!, Listening >> Result.CSV
  •    ) ELSE (
  •        Echo !ServerName!, Not Listening >> Result.csv
  •    )
  • )
  • REM ***END HERE***

The end result will be stored in a file called Result.csv.

About The Author

1 thought on “A Quick Tip To Check If A Port Is Listening On Multiple Computers”

  1. Looking for powershell script for getting the Specific Ports “5666, 5667, 61616, 62086, 62131” LISTENING status from multiple computers and output in CSV or EMAIL.

    Have this powershell command but not able to run for multiple computers.

    Get-NetTCPConnection -LocalPort 5666, 5667, 61616, 62086, 62131 |
    Select-Object -Property LocalAddress, LocalPort, RemoteAddress, RemotePort, State,
    OwningProcess, CreationTime | Format-Table -Autosize

Leave a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top