Exchange 2010 Mail Queue Stats Monitoring

Exchange Server 2010 Email Queue Stats Monitoring.

To view Mail queues in Exchange server 2010. Open the Exchange Management Console and click Toolbox, choose Queue Viewer.

There are three types of queues:

  • Submission Queue: contains messages waiting to be process by transport agents.
  • Unreachable Queue: contains messages that could not be delivered to destination.
  • Poison message Queue: contains messages that are harmful to the server.

Submission Queue is the most important queue to check as it holds messages to be delivered to recipients. If this queue freezes, no deliveries could be possible.

Because the EMC queue viewer takes a long time to load, we can use the Exchange Management Shell to query the queues. To view the submission queue using the Exchange Management Shell, do:

Get-Queue -Identity Submission | Select Identity, Status, MessageCount

In the example below, the message count is zero.

If we want to see all properties of the Submission queue, use the command without filtering:

Get-Queue -Identity Submission

Scheduled Task to Query Exchange Server Queue

In this second part of the lab, I will show you how to write a script, set it up on the Exchange server as a scheduled task to run every hour. When the messages in any queue reaches the specified threshold, an email will be sent to the administrator.

In the folder C:\script on the Exchange Server, create two script files:

QueueStats.bat and QueueStats.ps1.

The QueueStats.bat has the following contents:

powershell -executionpolicy bypass -file QueueStats.ps1

This means this batch file will call the PowerShell script QueueStats.ps1. And the following is the contents of the QueueStats.ps1 file:

$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://my-exchange.rf.local/PowerShell/ -Authentication Kerberos
Import-PSSession $s

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1

Connect-ExchangeServer -auto

$threshold = 10
$filename = "c:\Temp\QueueStats.txt"
Start-Sleep -s 10
if (Get-ExchangeServer | Where { $_.Name -eq "MY-EXCHANGE" } | get-queue | Where-Object { $_.MessageCount -gt $threshold })

Get-ExchangeServer | Where { $_.Name -eq "MY-EXCHANGE" } | get-queue | Where-Object { $_.MessageCount -gt $threshold } | Format-Table -Wrap -AutoSize | out-file -filepath c:\Temp\QueueStats.txt
Start-Sleep -s 10

$smtpServer = ""
Write-Host "Connecting to $smtpServer"
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = ""
$msg.Body = "Please see attached queue log file for queue information. "

Now in C: drive of the Exchange Server, create a folder C:\Temp so that queue details can be placed there.

Next, create a Scheduled Task to run QueueStats.bat every hour or so.