John Yassa's Blog

Home » 2012 » June » 03

Daily Archives: June 3, 2012

Check Exchange 2010 , 2010 SP1 , 2010 SP2 Queue size automatically

You can use a script check number of mails stuck at the queue and send you an alert if the number of mails exceeds 10 or whatever number you want

You can schedule this script to run every 15 min

#Script:   GetQueueMails.ps1
#Purpose:  This script collect info about the server Queue and trigeer an alert if the #               number of mail in queue exceeds 10 mails it send a full report
#about mails in queue to the address mentioned below
#Author:   John Yassa
# Email:
# Date:     June 2012
# Notes:
#            – tested with Exchange 2010 SP1 and Exchange 2010 SP2
#            – The log report output file will be created under “c:\queue.txt”

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

$filename = “C:\queue.txt”



if ($server.messagecount -gt 10)


$server | Where-Object { $_.MessageCount -gt 10 } | Format-Table -Wrap -AutoSize | out-file -filepath C:\TEMP\qu.txt

Start-Sleep -s 10

$smtpServer= “IP of SMTP Server”

$msg = new-object Net.Mail.MailMessage

$att = new-object Net.Mail.Attachment($filename)

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = “Mail From Address

$msg.To.Add(“Mail To Address“)



$msg.Body = “Kindly check attached queue log file for more information”




%d bloggers like this: