Solved

Exchange Queue Monitor Script

Posted on 2013-12-12
9
2,358 Views
Last Modified: 2013-12-12
I have found this Script that I'm trying to get to work on my Exchange 2007 Server. The response I'm getting back is


The term 'get-transportserver' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spellin
g of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\HBADMIN\Desktop\Queue2.ps1:2 char:32
+  $Servers = get-transportserver <<<<  | select ds-afs1
    + CategoryInfo          : ObjectNotFound: (get-transportserver:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
The term 'Get-Queue' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the n
ame, or if a path was included, verify that the path is correct and try again.
At C:\Users\ADMIN\Desktop\Queue2.ps1:6 char:19
+ $queue = Get-Queue <<<<  -server $srv.name | Select-Object NextHopdomain, Status, MessageCount
    + CategoryInfo          : ObjectNotFound: (Get-Queue:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: message"
At C:\Users\ADMIN\Desktop\Queue2.ps1:30 char:11
+ $smtp.Send <<<< ($message)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException


I'm thinking that the Script needs to call ExchangeManagement Snapin but it has not worked out for me yet. Also The Script is set to email me if the Queue exceeds the set limit.

Here is the script
$MessagesLimit = 1
 $Servers = get-transportserver | select name

 foreach($srv in $Servers){

$queue = Get-Queue -server $srv.name | Select-Object NextHopdomain, Status, MessageCount
if($queue -ne $null){
foreach ($element in $queue){
if ($element.MessageCount -gt $MessagesLimit){
$Body += "$srv - $($element.NextHopDomain) queue length: $($element.MessageCount)."
}

}
}
else {
$Body += "Can't read queue on server: $srv"
}
 }

 #send email
 if ($Body){
$FromAddress = "sender@gmail.com"
$ToAddress = "user1@domain.com , user2@domain.com"
$MessageSubject = "Exchange Queue Alert"
$MessageBody = $Body
$smtp = New-Object System.Net.Mail.SMTPClient –ArgumentList smtp.gmail.com
$smtp.Credentials = New-Object System.Net.NetworkCredential("sender@gmail.com", "password" )
$smtp.EnableSsl = $true
$smtp.Port = 587
$smtp.Send($message)
 }

Open in new window

0
Comment
Question by:Bill Warren
[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
  • 5
  • 3
9 Comments
 
LVL 19

Expert Comment

by:jss1199
ID: 39714640
It does need the ExchangeManagement Snapin - have you loaded the snapin in a PS windows and executed the script from there?
0
 
LVL 19

Accepted Solution

by:
jss1199 earned 500 total points
ID: 39714644
add to your script, Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
0
 

Author Comment

by:Bill Warren
ID: 39714690
After adding
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
to the very top of the script, I get this

Add-PSSnapin : Cannot add Windows PowerShell snap-in Microsoft.Exchange.Management.Powershell.Admin because it is already added. Verify
 the name of the snap-in and try again.
At C:\Users\HBADMIN\Desktop\Queue2.ps1:1 char:13
+ Add-PSSnapin <<<<  Microsoft.Exchange.Management.Powershell.Admin
    + CategoryInfo          : InvalidArgument: (Microsoft.Excha...owershell.Admin:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
 
Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: message"
At C:\Users\HBADMIN\Desktop\Queue2.ps1:31 char:11
+ $smtp.Send <<<< ($message)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:Bill Warren
ID: 39714695
After removing the Snapin, I now just get this

Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: message"
At C:\Users\HBADMIN\Desktop\Queue2.ps1:31 char:11
+ $smtp.Send <<<< ($message)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
0
 

Author Comment

by:Bill Warren
ID: 39714706
I added the line
$message = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody

and now I get the email however the body says

Can't read queue on server: Can't read queue on server:
0
 
LVL 37

Expert Comment

by:Jamie McKillop
ID: 39714729
Hello,

Change these lines:

$FromAddress = "sender@gmail.com"
$ToAddress = "user1@domain.com , user2@domain.com"
$MessageSubject = "Exchange Queue Alert"
$MessageBody = $Body

to:

$Message.From = "sender@gmail.com"
$Message.To.Add = "user1@domain.com , user2@domain.com"
$Message.Subject = "Exchange Queue Alert"
$Message.Body = $Body

-JJ
0
 
LVL 19

Expert Comment

by:jss1199
ID: 39714732
are you running this locally on the exchange sever?
0
 

Author Comment

by:Bill Warren
ID: 39714776
it is running locally on the exchange server
0
 

Author Closing Comment

by:Bill Warren
ID: 39714831
It worked fine. I have another question which I will open a new Ask
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

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.
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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