Solved

Monitor queue length Exchange 2007 Powershell

Posted on 2013-01-22
4
1,930 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 38805500
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
ID: 38805565
Hi,

Nexthopdomain that has a queue greater than 100.

Thanks.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38805757
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
ID: 38813441
Excellent, worked perfectly! Thanks Subsun, much appreciated.
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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 …

739 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