Wednesday, May 21, 2014

Test Transport Servers

Using native tools, I have been looking for a way to test the transport services on all my Exchange 2010 services. This one-liner, will attempt to send an email via each transport server and if it get's any error during the process, it will send an email to the admin that it failed.

$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