[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2439
  • Last Modified:

Exchange Queue Monitor Script

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
Bill Warren
Asked:
Bill Warren
  • 5
  • 3
1 Solution
 
jss1199Commented:
It does need the ExchangeManagement Snapin - have you loaded the snapin in a PS windows and executed the script from there?
0
 
jss1199Commented:
add to your script, Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
0
 
Bill WarrenIT ManagerAuthor Commented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Bill WarrenIT ManagerAuthor Commented:
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
 
Bill WarrenIT ManagerAuthor Commented:
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
 
Jamie McKillopCommented:
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
 
jss1199Commented:
are you running this locally on the exchange sever?
0
 
Bill WarrenIT ManagerAuthor Commented:
it is running locally on the exchange server
0
 
Bill WarrenIT ManagerAuthor Commented:
It worked fine. I have another question which I will open a new Ask
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now