Solved

Exchange Queue Monitor Script

Posted on 2013-12-12
9
2,320 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:afsfire
  • 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:afsfire
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
 

Author Comment

by:afsfire
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:afsfire
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:afsfire
ID: 39714776
it is running locally on the exchange server
0
 

Author Closing Comment

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

Featured Post

3 Use Cases for Connected Systems

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

Question has a verified solution.

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

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now