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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | < ################################################################## ## Check Trasnsport Servers NDR emails in queues and report to ## ## administrators via eamil ## ## ## ## Modify values under VARS section for email settings ## ## ## ###################################################################> #Add Exchange Tools Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue; ## START VARS $emails = @( ) $mailSubject = "Daily NDR Report for DOMAIN" $mailServer = "mail.domain.com" ## FUNCTIONS function msg_get_queue() { $mQ = @() $mQ = Get-ExchangeServer | ? {$_.isHubTransportServer -eq $true} | get-queue | ? {$_.MessageCount -gt 0} return $mQ } function msg_get_msgFromQ($i) { $mFQ = @() foreach ($x in $i) { $mFQ += ($x | Get-Message) } return $mFQ } function msg_get_details($i) { $mQD = @() foreach ($svr in (Get-ExchangeServer | ? {$_.isHubTransportServer -eq $true})) { $mQD += Get-MessageTrackingLog -MessageId $i -Server $svr.Name | ? {$_.EventID -eq "RECEIVE"} } return $mQD } ## FUNCTION TO GET Q AND BUILD EMAIL function msg_get_NDR_details() { $html = " <meta http-equiv="" content="" charset="us-asciiamp;"amp;"" /> <meta name="Generator" content="" /> |
”
foreach ($subQ in (msg_get_queue)) {
foreach ($subMsg in $subQ) {
$html += ”
”
}
}
$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 += ”
| ||||||||||||||
Total Messages in this Queue: $($subMsg.MessageCount) |
1 2 3 4 5 6 7 | " return $html } #SEND EMAIL Send-MailMessage -SmtpServer $mailServer -To $emails -From $fromAddress -subject $mailSubject -bodyAsHtml (msg_get_NDR_details) |
Excellent article. I’m experiencing msny of these issues as well..
Get an small brief idea for PowerShell script to Identify Delays or Failures in Exchange Transport Queue and send Email. Use the post.