PowerShell script to Identify Delays or Failures in Exchange Transport Queue and send Email

I wanted some transparency into the transport queue on Exchange 2010 mail servers to check or identify potential email failures or delays. Most of the time these are emails that were sent to “no-reply” addresses or typos in the recipient’s email address. I wrote a quick PowerShell script that checks each transport server for any queue that has one or more messages, finds each email in that queue, and then searches message tracking logs regarding that message. It uses my “go-to” HTML Email theme/template to compose an email with the nextHopDomain and each message for that domain. This includes some common info to help identify the message, sender, recipient, error, and etc. I’m sure the script can be tweaked or modified, but I wanted to use functions so I can use them for other scripts. Modify the email settings/values for your needs.
” foreach ($subQ in (msg_get_queue)) { foreach ($subMsg in $subQ) { $html += ”
$($subMsg.NextHopDomain)
$($subMsg.Status) due to $($subMsg.DeliveryType), will try again on $($subMsg.NextRetryTime) Last Error: $($subMsg.LastError)
” foreach ( $subDetails in (msg_get_msgFromQ($subMsg)) ) { $rows = msg_get_details($subDetails.InternetMessageId) foreach ($row in $rows) { $html += ” ” } } $html += ”
EventID Source Sender Recipients MessageSubject TotalBytes ServerHostname
$($row.EventID) $($row.Source) $($row.Sender) $($row.Recipients) $($row.MessageSubject) $($row.TotalBytes) $($row.ServerHostname)
Total Messages in this Queue: $($subMsg.MessageCount)
” } } $html += ”

2 comments

Leave a comment

Your email address will not be published. Required fields are marked *