John Yassa's Blog

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

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:    John.nassan@yahoo.com
# 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”

$server=get-queue

$server.messagecount

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.To.Add(“user2@domain.com“)

$msg.Subject = “HUB SERVER QUEUE THRESHOLD REACHED”

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

$msg.Attachments.Add($att)

$smtp.Send($msg)

}


2 Comments

  1. Chris Burkey says:

    i am trying to set up this script and the txt files are not being created nor is the email can you loan any advice

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: