Queue reporting in Exchange 2010 – Guest Post by Jaap Wesselius

Second in our series of Guest posts by Exchange MVP’s is Jaap Wesselius, exploring the reporting capabilities on historical SMTP queues. Reporting is a perennial issue for Exchange admins and I'm delighted for Jaap to demystify it so well.

Jaap Wesselius is an independent consultant from The Netherlands focusing on (Microsoft) Business Productivity solutions. Prior to becoming an independent consultant, Jaap worked for 8 years for Microsoft Services in The Netherlands, specializing in Exchange Server. Jaap has a Bsc in Applied Physics & Computer Science, is an MCSE, MCITP and MCT, and has consistently been awarded the Microsoft MVP Award (Exchange Server, fifth year now) for his contributions to the Dutch Exchange community

Queue reporting

  On your Exchange 2010 server there are not a lot of possibilities to have a historical look at the SMTP queues. Of course you can use the Queue Viewer in the Exchange Management Console but this is an instant view of the SMTP queues. Personally I like the Exchange Management Shell cmdlet "Get-Queue" a bit more because you can select all servers with only one command: Get-TransportServer | Get-Queue This will give you an overview of all SMTP Queues on all Hub Transport Servers. With the Shell you also have the option to select only the properties you want to see using the "Select" operator. For example, to see only the Identity, Status, Number of messages and the domain of the SMTP queues you can use the following command: Get-Queue | Select Identity,Status,MessageCount,NextHopDomain Combine this with the previous command and you'll get a nice overview of your SMTP queues: Get-TransportServer | Get-Queue | Select Identity,Status,MessageCount,NextHopDomain This output is shown on the console, but it would be nice if it can be stored on hard disk for logging purposes. Powershell has a command for this: "ConvertTo-HTML" that can be used to convert console output to HTML formatted output. This HTML output is still shown on the console, but can be saved to disk using the "Out-File" command. The previous command to get the Queue information would now look like: Get-TransportServer | Get-Queue | Select Identity,DeliveryType,Status,MessageCount,NextHopDomain, LastRetryTime,NextRetryTime | ConvertTo-HTML | Out-File C:TempQueueInfo.html Although useful, the output is really awful to look at: To work around the ugly lay-out we have to change settings for all the cells in the table that's shown in this overview. The layout can include the background colour, the font type, size and colour, the alignment etc. To get a nicer looking HTML file, gather some more information and to create a unique filename the Powershell string that was used earlier will be converted into a small Powershell script. To accomplish this we have to work with HTML Styles that define all these settings, and this is style is stored in a variable called $BodyStyle: $BodyStyle = "<style>" $BodyStyle = $BodyStyle + "BODY{background-color:peachpuff;}" $BodyStyle = $BodyStyle + "TABLE{border-width: 1px;border-style: solid; border-color: black;border-collapse: collapse;}" $BodyStyle = $BodyStyle + "TH{border-width: 1px;padding: 0px; border-style: solid;border-color: black;background-color:thistle}" $BodyStyle = $BodyStyle + "TD{border-width: 1px;padding: 0px; border-style: solid;border-color: black;background-color:PaleGoldenrod}" $BodyStyle = $BodyStyle + "</style>" The variable $BodyStyle is then added to our previous command to get a better lay-out of the HTML output: Get-TransportServer | Get-Queue | Select Identity,DeliveryType,Status,MessageCount,NextHopDomain,LastRetryTime, NextRetryTime | ConvertTo-Html -head $BodyStyle | Out-File C:TempQueueInfo.html When the above is stored in a Powershell script, for example c:tempqueue.ps1, and it is run from an Exchange Management Shell command prompt we get the following output: This is a much better view than the original one. But instead of storing a file on disk it is also possible to send the output to somebody. To do this we have to create a new e-mail message(called $Msg) and parse the output of the previous command into the e-mail message, so the following code is added to our Queue information Powershell script: $Msg = new-object system.net.mail.MailMessage $msg.IsBodyHtml = $True $msg.Body = $Queue $msg.Subject = "Hub Transport Queue Information" $msg.To.add("postmaster@wesselius.info") $msg.To.add("jaap@wesselius.info") $msg.From = "postmaster@wesselius.info" $SmtpClient = new-object system.net.mail.smtpClient $smtpclient.Host = '<your SMTP relay server>' $smtpclient.Send($msg) Note: the $Queue variabele contains the data that was collected using the Get-Queue command. The $Queue variable is populated as follows (this has to be changed in our script as well): $Queue = Get-TransportServer | Get-Queue | Select Identity,DeliveryType,Status,MessageCount,NextHopDomain,LastRetryTime, NextRetryTime | ConvertTo-Html -head $BodyStyle When the new script is run the information is collected, formatted and sent using SMTP to a recipient. After some time the new message arrives in our inbox: The last part is to schedule our Powershell script on a regular basis. It is not possible to schedule Powershell scripts from the Windows Task Scheduler, so the Powershell script in included in a batch file. Create a batch file using Notepad called "QueueInfo.cmd" and store the following in this file: Powershell.exe -PSConsoleFile "C:Program FilesMicrosoftExchange Serverv14binexshell.psc1" -command ". 'C:Tempqueue.ps1'" The QueueInfo.cmd file can now be used in the Windows Task Scheduler. This way we get Queue information on a regular basis, right into the Inbox!