What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags

View all Tags

A way to count mails in all queues of a MS Exchange Server 2007



It took me hours to get this running... This script counts all mails in all queues on a MS Exchange Server 2007 and returns the sum to PRTG. Tested with PRTG

Option Explicit
' Script by [email protected] 2011
' Script to count mails in ALL queues on a Microsoft Exchange Server 2007.
' This script is designed to put the values back to PRTG for monitoring.
' 1)  Copy this script to
'     <PRTG Installation Path>\Custom Sensors\EXE on the target server
'     where your devive is configured.
' 2)  Create a new Custom Sensor (EXE/Script) on a device (most likely the 
'     device which is running the Microsoft Exchange Server 2007).
' 3)  Give the Sensor a name
' 4)  Under "EXE/Script" choose this script
' 5)  Under "Parameters" type the following: SERVERNAME WARNING_VALUE_1 WARNING_VALUE_2
' 6)  Under "Channel Name" type for example "MS EXC Queue"
' 7)  Under "Unit String" type for example "mails"
' 8)  Save.

Dim objPing
Dim objStatus
Dim objShell
Dim strComputer, strPSCommand, strShellCommand, intMessageCount, intOK, intWarning1, intWarning2

'Get the Parameters  
strComputer = Wscript.Arguments(0)
intWarning1 = Wscript.Arguments(1)
intWarning2 = Wscript.Arguments(2)

'Check if Server is online 
'(this block can be simply removed if you do not want to check the onlien state,
'but note that the Sensor remains OK (green) if the server goes offline)
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
  If IsNull(objStatus.ReplySize) Then
    WScript.Echo "Server " & strComputer & " is offline!"
  End If
Set objPing = Nothing
Set objStatus = Nothing

'Run Powershell to count the messages
strPSCommand = "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin; $MessageCount = get-queue -server " & strComputer & " | foreach -begin {$total=0} -process {$total+=$_.messageCount} -end {$total}; exit $MessageCount"
strShellCommand = "c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -command " & strPSCommand
Set objShell = CreateObject("WScript.Shell")
intMessageCount = objShell.Run(strShellCommand, , True)
Set objShell = Nothing

'Return values and messages to PRTG
If intMessageCount < intWarning1 Then
  WScript.Echo intMessageCount & ":OK"
ElseIf intMessageCount < intWarning2 Then
  WScript.Echo intMessageCount & ":Unlikely many mails in Queue"
  WScript.Echo intMessageCount & ":Too many mails in Queue, please check"
End if

Enjoy, Mike

count exchange-2007 prtg queue

Created on Jul 28, 2011 3:46:54 PM

Last change on Jul 28, 2011 5:10:38 PM by  Torsten Lindner [Paessler Support]

2 Replies




thank you very much for this very good and helpful script! Sorry, for the delay on the publishing. Just one note, it might be necessary to change the path to the Powershell.exe in the script:

strShellCommand = "c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -command " & strPSCommand

best regards.

Created on Aug 15, 2011 11:57:48 AM by  Torsten Lindner [Paessler Support]




yes maybe in some special cases (eg. Server is installed not in C:\windows\...). Here is a little improvement of this statement: strShellCommand = "%windir%\sysnative\windowspowershell\v1.0\powershell.exe -command " & strPSCommand

Created on Aug 16, 2011 8:18:42 AM

Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.