Solved

Exchange Queue Monitor Script

Posted on 2013-12-12
9
2,310 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
Shouldn't all users have the same email signature?

You wouldn't let your users design their own business cards, would you? So, why do you let them design their own email signatures? Think of the damage they could be doing to your brand reputation! Choose the easy way to manage set up and add email signatures for all users.

 

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

Shouldn't all users have the same email signature?

You wouldn't let your users design their own business cards, would you? So, why do you let them design their own email signatures? Think of the damage they could be doing to your brand reputation! Choose the easy way to manage set up and add email signatures for all users.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

12 Experts available now in Live!

Get 1:1 Help Now