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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #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 = @{ Subject = "Server Status Check" SMTPServer = "YOUR SMTP SERVER" Priority = "High" Body = $body } Send-MailMessage @NotiEmail |
Disclaimer: All posts and opinions on this site are provided AS IS with no warranties. These are our own personal opinions and do not represent our employer’s view in any way.
This article currently have 9,827 views
Latest posts by Saugata (see all)
This work is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International License.