Solved

Monitor queue length Exchange 2007 Powershell

Posted on 2013-01-22
4
1,915 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
This video discusses moving either the default database or any database to a new volume.

828 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