top of page

PowerShell - Port Scanner, one port, from text list of Computers/Servers

  • Writer: Jon Boyette
    Jon Boyette
  • Jan 7, 2022
  • 1 min read


foreach($line in [System.IO.File]::ReadLines("C:\TEMP\TESTING2OU.txt"))

{

$servers=$line

#$Why=Read-Host "Enter Port Number to Check from C:\Temp\Testing2ou.txt List of Computers"

# Define the port number you need to test (eg: 3389 for RDP):

$portToCheck = '445'


foreach ($server in $servers) {


If ( Test-Connection $server -Count 1 -Quiet) {


try {

$null = New-Object System.Net.Sockets.TCPClient -ArgumentList $server,$portToCheck

$props = @{

Server = $server

PortOpen = 'Yes'

}

}


catch {

$props = @{

Server = $server

PortOpen = 'No'

}

}

}


Else {


$props = @{

Server = $server

PortOpen = 'Server did not respond to ping'

}

}


New-Object PsObject -Property $props


}

}


This, similar to the previous port scanner, only this one scans many machines one port, the other scans many ports one machine, ironically it isnt as easy as thought to combine these, thus I have both.

 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page