Solved

Exchange Queue Monitor Script

Posted on 2013-12-12
9
2,345 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
  • 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

840 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