Powershell Email Notifications

Using the below powershell code, we can ping the servers and set up email notifications, if any server went down. This could scheduled using Task Scheduler and set to run as frequently as possible to get notified as early as possible, in the event of a shut down.


$ServerList = "ServerA","ServerB","ServerC","ServerD"

foreach ($Server in $ServerList)
{
if (-Not(test-Connection -ComputerName $Server -Count 2 -Quiet ))
{
Send-MailMessage -To "xyz@nodomainexists.com","abc@nodomainexists.com" -Subject "The $Server server is not responding." -Body "The $Server server is not responding. This notification is coming from Powershell Script running on MachineName." -SmtpServer yourSMTPServer -From "def@nodomainexists.com"
}
}