Few days back I was asked to create a script, which will check RDP port status of multiple servers and send the result as an email notification. I have searched for few, but unfortunately there was no ready script for that. I decided to build one using PowerShell, and came out with following script.
Hope this script might help you as well.
#Which port to scan
$port = 3389
#Path of the input server list
$hostns=Get-Content D:Servers.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 = "[email protected]"
To = "[email protected]"
Subject = "Server Status Check"
SMTPServer = "YOUR SMTP SERVER"
Priority = "High"
Body = $body
}
Send-MailMessage @NotiEmail
The Credential-Free Watchdog: Mastering Event-Driven App Automation
We have all been there. You are an automation lover. You have…
Ditching PsExec – Running Interactive SYSTEM Shells Natively in PowerShell
If you’ve spent any time in Windows System Administration over the last…
From The Blinking Cursor to The Thinking Machine: A Memoir of Automation
There is a specific kind of silence that only exists in a…
Setup your own Monitoring – Disk Space Utilization Monitoring tool for free
It is always recommended to keep tracking of the disk space utilization…