Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Monitor queue length Exchange 2007 Powershell

Posted on 2013-01-22
4
Medium Priority
?
1,960 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 2000 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

Introducing the WatchGuard 420 Access Point

WatchGuard's newest access point includes an 802.11ac Wave 2 chipset, providing the fastest speeds for VoIP, video and music streaming, and large data file transfers. Additionally, enjoy the benefits of strong security as the 3rd radio delivers dedicated WIPS protection!

Question has a verified solution.

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

Check out this step-by-step guide for using the newly updated Experts Exchange mobile app—released on May 30.
I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
The viewer will learn how to dynamically set the form action using jQuery.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

688 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