Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Monitor queue length Exchange 2007 Powershell

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

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

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

Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

877 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