Solved

Monitor queue length Exchange 2007 Powershell

Posted on 2013-01-22
4
1,876 Views
Last Modified: 2013-01-24
Hi,

I have the script below that generates an email when a queue goes over 100.

#Get Queue data from transport servers
$a = Get-TransportServer -identity ***** | Get-Queue | Select-Object MessageCount | ?{$_.MessageCount -gt '0'} | Measure-Object MessageCount -sum
#If the queue is higher than the number set below, send email, if not , exit.
IF ($a.sum -gt 100) {
$emailFrom = "exch.queue@***.com"
$emailTo = "mon.team@***.com"
$subject = "Exchange Queue Alert"
$body = "Current Email Queue: "
$body += $a.sum | Out-String
$smtpServer = "****" # Replace with your SMTP Server IP
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
EXIT
}
ELSE {
EXIT
#EOF
}

Works well. I also need to add nexthopdomain and identity to the body of the email along with messagecount. I've tried this but I still only get messagecount.....

#Get Queue data from transport servers
$a = Get-TransportServer -identity ***** | Get-Queue | Select-Object Nexthopdomain,MessageCount,Identity | ?{$_.MessageCount -gt '0'} | Measure-Object MessageCount -sum
#If the queue is higher than the number set below, send email, if not , exit.
IF ($a.sum -gt 100) {
$emailFrom = "exch.queue@***.com"
$emailTo = "mon.team@***.com"
$subject = "Exchange Queue Alert"
$body = "Current Email Queue: "
$body += $a.sum | Out-String
$smtpServer = "****" # Replace with your SMTP Server IP
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
EXIT
}
ELSE {
EXIT
#EOF
}

Any help, or better way of doing this would be much appreciated.

Thanks
0
Comment
Question by:glp007
  • 2
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
Are you looking for Nexthopdomain's which has queue count greater than 100 or just all Nexthopdomain's from the server?
0
 

Author Comment

by:glp007
Comment Utility
Hi,

Nexthopdomain that has a queue greater than 100.

Thanks.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
Comment Utility
Just to clarify... As per your current script, you are getting alert if the total queue count is greater than 100. So I guess this is a separate alert and you need to get alert only if the Nexthopdomain queue count is greater than 100.

#HTML head
$a = "<style>"
$a = $a + "BODY{background-color:White;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>"

$Result = Get-TransportServer -identity "HUBServer" | Get-Queue | ?{$_.MessageCount -gt '100'} | Select-Object Nexthopdomain,MessageCount,Identity

IF ($Result) {
Send-MailMessage `
-Subject "Exchange Queue Alert" `
-Body $($Result | ConvertTo-HTML -head $a | Out-String) `
-From "exch.queue@***.com" `
-To "mon.team@***.com" `
-SmtpServer "SMTPSERVER" `
-BodyAsHtml
}

Open in new window



Without any HTML formatting..
$Result = Get-TransportServer -identity "HUBServer" | Get-Queue | ?{$_.MessageCount -gt '100'} | Select-Object Nexthopdomain,MessageCount,Identity

IF ($Result) {
Send-MailMessage `
-Subject "Exchange Queue Alert" `
-Body $($Result | ConvertTo-HTML | Out-String) `
-From "exch.queue@***.com" `
-To "mon.team@***.com" `
-SmtpServer "SMTPSERVER" `
-BodyAsHtml
}

Open in new window

0
 

Author Closing Comment

by:glp007
Comment Utility
Excellent, worked perfectly! Thanks Subsun, much appreciated.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now