Test-Port

This is a simple port scanner that you can run against one or more hosts and check one or more ports to see if they are open.

Test-Port.ps1
 
 
 
 
 
4.4 Star
(54)
42,211 times
Add to favorites
Networking
4/20/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Result empty
    2 Posts | Last post January 10, 2020
    • Hi guys,
      
      I'm trying to use the script but I have some difficulty with the UDP test 
      When I check a UDP port the result is always empty.
      
      instead with the TCP ports, no problem reported 
      
      Is there someone that can help me?
      
      Thank you in advanced
      
      PS C:\> Test-Port -computer 192.168.4.86 -port 427 -UDP
      
      
      Server   : 
      Port     : 
      TypePort : 
      Open     : 
      Notes    : 
      
    • Hi,
      had the same result (with port 53) when the firewalls don't allow 53 udp traffic. 
      But 53 tcp traffic was allowed, so <test-connection -port 53 -ComputerName DNSServer> showed a valid TCP connection. (TcpTestSucceeded : True)
      As soon as i tried Test-Port in a network segment with 53 TCP/UDP allowed it worked. 
      
      Server   : xxx.xxx.xxx.xxx
      Port     : 53
      TypePort : UDP
      Open     : True
      Notes    : 01?9/2020 13:09:53
      
      You may try nmap to verify in your network to ensure that 427 UDP is not open, or you move into the same network segment, so no firewall is in place. 
  • Not any output at all
    2 Posts | Last post February 19, 2019
    • Hi there,
      when running .\Test-Port -comp 8.8.8.8 -port 3389 I do not get any output at all.
      Nothing, just a new blank sentence. When piping to CSV, the CSV is also empty.
      
      Any ideas ? This happens on W10 and W2012r2.
      
      greets, Thomas
    • solution is, as one user below noted
      ... it have to be pre-loaded using ". .\Test-Port.ps1" (to new users, notice the space between the leading dots)
      
      After that you can use direct "Test-port" call
  • UDP always returns "TRUE"
    1 Posts | Last post August 01, 2018
    • Hello,
      
      Thank you so much for nice script
      I'm still facing the bug, UDP port always returns "TRUE" even this port has not opened on my computer.
      Do you have any idea to fix it?
      Have a pleasant day!
      
      Best regards
      
  • No output
    4 Posts | Last post May 17, 2018
    • Hi all,
      I am trying to run the scripts but I don't get any output, any idea?
      
      Thanks
      
      Claudio
    • Did you get any response? Sadly, this does not give any output for me too. 
    • Have I mentioned yet today how much I DESPISE strict mode?  Aargh.
      
      For those also getting no output (and other issues below).....yet another demonstration of how detrimental strictmode can be:
      
      ------------------------------------------
      
      C:\Scripts> Test-Port -computer SERVER01 -port 53
      
      
      Server   :
      Port     :
      TypePort :
      Open     :
      Notes    :
      
      C:\Scripts> Set-StrictMode -off
      
      C:\Scripts> Test-Port -computer SERVER01 -port 53
      
      
      Server   : SERVER01
      Port     : 53
      TypePort : TCP
      Open     : True
      Notes    :
      
      
      ------------------------------------------
      
      So, try it back-to-back with a simple "Set-StrictMode -Off" in between and I bet anything it resolves your issues.
      
    • Hi,
      Combining several answers below led me to the following (which works) though I was also not getting any output initially:
      Run from the folder where you have the script located:
      powershell
      Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
      Set-StrictMode -off
      . .\Test-Port.ps1
      Test-Port -comp dc1 -port 17 -udp  (sample run - notice no leading ".\" or trailing ".ps1")
  • This script does not work
    2 Posts | Last post January 31, 2018
    • I dot sourced it. I still see the following:
      
      
      PS E:\Scripts> .\Test-Port.ps1 -computer '192.168.0.96' -port 135
      
      PS E:\Scripts> Test-Port.ps1 -computer '192.168.0.96' -port 135
      Test-Port.ps1 : The term 'Test-Port.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, 
      verify that the path is correct and try again.
      At line:1 char:1
      + Test-Port.ps1 -computer '192.168.0.96' -port 135
      + ~~~~~~~~~~~~~
          + CategoryInfo          : ObjectNotFound: (Test-Port.ps1:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
    • Hi Mike,
      
      Make sure that the the powershell script, test-port.ps1, is in the same  directory that you are executing the command from, and you don't need .\ when executing it if you have already dot sourced it.
  • How to output to text and csv?
    2 Posts | Last post September 18, 2017
    • 
      Added these after the $report output:
      
      $datestring = (Get-Date).ToString("s").Replace(":","-") 
      $report | Export-csv report$datestring.csv -NoTypeInformation
      Add-Content report$datestring.txt $report
      
      This will help you to have results stored in a file with unique filenames so you don't overwrite your results.
      Checking a bunch of ports on a bunch of servers using this command:
      
      test-Port -computer (get-content .\hosts.txt) -port (get-content .\ports.txt)
      
      Takes about 20 minutes for 20~ hosts.
      Hope this help someone.
    • Hi Cesar,
      
      All I did was pipe output to export-csv.
      
      test-Port -computer (get-content .\hosts.txt) -port (get-content .\ports.txt) | export-csv .\results.csv
  • Works like a charm!
    1 Posts | Last post September 18, 2017
    • Thank you Boe Prox!
  • Status for each Port
    4 Posts | Last post September 18, 2017
    • Thanks a lot for the lovely function, working perfectly. 
      I tried to modify by my way but no luck. 
      
      I was trying to get value for each port and tab should be as port name, but each port status value is not coming individually.
      
      Need assistance
      
      How I am getting output..
      
      SourceServer  DestinationServer      TCP_80                 TCP_443               TCP_8081              TCP_8082             
      ------------  -----------------      ------                 -------               --------              --------             
      Test1          Test2  		{True, True}           {True, True}          {True, True}          {True, True}         
      Test1          Test2  		{True, True}           {True, True}          {True, True}          {True, True}         
      Test1          Test2  		{False, True}          {False, True}         {False, True}         {False, True}        
      Test1          Test2  		{False, True}          {False, True}         {False, True}         {False, True}
    • Here is the foreach look ...
      
      foreach($ePOServer in $ePOServers) {
      
      $LocalServer = $env:COMPUTERNAME
      #$TCP80 = test-port -comp $ePOServer -port 80 -tcp 
      #$UDP80 = test-port -comp $ePOServer -port 80 -udp
      foreach ($Port in $Ports) {
      $checkport = Test-Port -computer $ePOServer -port $Port -UDP -TCP
      $Port = @()
          
      
      $ResultsPort = New-Object Object
      $ResultsPort | Add-Member -Type NoteProperty -Name "SourceServer" -Value $LocalServer
      $ResultsPort | Add-Member -Type NoteProperty -Name "DestinationServer" -Value $ePOServer
      
      foreach ($P in $Ports) {
      $Value = $checkport.open
      $ResultsPort | Add-Member -Type NoteProperty -Name "TCP_$($P)" -Value $Value
      }
      
      
      $AllPortResults += $ResultsPort
      }
      
      }
    • Hi Amol,
      
      Courtesy Sarath Pillai.
      
      I would like to import CSV file in below format and send email alert when False result occurring with specific line. Can somebody help me?
      Customer	Source	Destination	Port	Result
      ABC	10.XX.XX.XX	10.XX.XX.XX	22	True
      DEF	10.XX.XX.XX	10.XX.XX.XX	443	False
    • or you can just pipe the output to export-csv.
  • Running the Script
    4 Posts | Last post May 02, 2017
    • No matter what I try I can not get the script to do anything. I know that people say to dot source first but I am trying that ( maybe Im just doing it wrong). I put the script on the root of my C drive. I using powershell window launched as admin and change the directory to C:  
      
      I have tried from the following
      .\Test-Port.ps1 Test-Port -computer 192.168.1.45 -port 80
      . .\Test-Port.ps1 Test-Port -computer 192.168.1.45 -port 80
      .\Test-Port.ps1 Test-Port -computer "192.168.1.45" -port 80
      .\Test-Port.ps1 -computer 192.168.1.45 -port 80
      
      and a few other combination. 
    • Hi there, to use the script correctly, yo must enter the computer IP between single quotes, here is an example:
      
      Test-Port -computer 'serverIP' -port 80
      
      there is an example inside the script code.-
      
    • It's . .\Test-Port.ps1
      
      Pay attention to the space between the two dots ;)
    • It's . .\Test-Port.ps1
      
      Pay attention to the space between the two dots ;)
      
      Update: type it as it is, and hit enter, then start using the cmdlet Test-Port normally without any dots or slashes.
  • Why is preloading required?
    1 Posts | Last post February 25, 2017
    • Why does it have to be pre-loaded using ". .\Test-Port.ps1" (to new users, notice the space between the leading dots), because of the parameters?
      
      Why don't the instructions/leading comments include the need to do this?
1 - 10 of 24 Items