$str="";$Invalid=@();get-transportserver | %{send-mailmessage -to invalid@example.com -from $($_.name+"@example.com") -Subject $_.name -SmtpServer $_.name -ErrorVariable ERRORS -erroraction silentlycontinue;if ($errors) { [array]$Invalid += $_.name}};If($invalid){$invalid | %{Get-ExchangeServer $_} | select name, site | convertto-html | %{$str+= $_}; Send-MailMessage -to "Admin@Example.com" -from "SMTP-DOWN@Example.COM" -Subject "SMTP ERRORS" -SmtpServer SMTP_Server_Name -Body $str -bodyashtml }
Now, it makes one assumption that the server you send the alert through is valid.
Part 1: Initialize variables
$str="";$Invalid=@();
Part 2: Send a test message, if get error response, capture it and record it in $INVALID
get-transportserver | %{send-mailmessage -to invalid@example.com -from $($_.name+"@example.com") -Subject $_.name -SmtpServer $_.name -ErrorVariable ERRORS -erroraction silentlycontinue; if ($errors) { [array]$Invalid += $_.name}} # $INVALID will contain the TransportServer name when found invalid.
Part 3: Process server names, create message body, send email.
If($invalid) {$invalid | %{Get-ExchangeServer $_} | select name, site | convertto-html | %{$str+= $_}; Send-MailMessage -to "Admin@Example.com" -from "SMTP-DOWN@Example.COM" -Subject "SMTP ERRORS" -SmtpServer SMTP_Server_Name -Body $str -bodyashtml }
The message received contains the servername and the AD site the server resides in.
No comments:
Post a Comment