top of page

PowerShell - Check Port from List of Servers with email results

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


#Which port to scan

$port = 445

#Path of the input server list

$hostns=Get-Content c:\temp\yourtextfile.txt

$body = @()

foreach ($hostn in $hostns)

{

$PortCon = new-object System.Net.Sockets.TcpClient($hostn, $port)

if ($PortCon.Connected -eq 'True')

{

$body +="$hostn Server listening to port $port"

$PortCon.Close()

}

else

{

$body +="$hostn Server not responding to $port"

}

}

$body = $body | Out-String

$NotiEmail = @{

From = "add email address"

To = "add email address"

Subject = "Server Status Check"

SMTPServer = "Add SMTP server"

Priority = "High"

Body = $body

}

Send-MailMessage @NotiEmail


 
 
 

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