Inspect queue (VBScript)

This code can be found in Chapter 7 of Exchange Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This script was originally published in the Exchange Cookbook,
' (http://www.exchangebookcook.com). Written by Paul Robichaux, 
' Missy Koslosky, and Devin Ganger. Redistributed with permission 
' of the publisher, O'Reilly & Associates.

' This code enumerates the messages within a given queue.

' ------ SCRIPT CONFIGURATION -----
' The host name of the Exchange server
strHostname = "<ExchangeServerName>"
' e.g., red-exch02 ' Name of the SMTP queue to search for messages
strQueueName = "<SMTPQueueName>"
' e.g., 3sharp.com
' ------ END CONFIGURATION --------

' Get the Exchange Namespace WMI object
Set objWMIExch =  GetObject("winmgmts://" & strHostname &_
   "/root/MicrosoftExchangeV2")
' Get the list of queues and process our desired queue
Set objQueuesList = objWMIExch.InstancesOf("Exchange_SMTPQueue")
For Each objQueueInst in objQueuesList
   ' Make sure this queue is the one we're looking for; if not, skip it
   If objQueueInst.QueueName = strQueueName Then
      strMsgInfo = strMsgInfo & "Queue: " & objQueueInst.QueueName & " (" &_
         objQueueInst.QueueID & ")" & VbCrLF
      Set objMsgsList = objWMIExch.ExecQuery ("Select * From " &_
         "Exchange_QueuedSMTPMessage Where ProtocolName='SMTP' And LinkId='" &_
         objQueueInst.LinkID & "' And LinkName='" &_
         objQueueInst.LinkName & "' And QueueId='" &_
         objQueueInst.QueueID & "' And QueueName='" &_
         objQueueInst.QueueName &"' And VirtualMachine='" &_
         objQueueInst.VirtualMachine & "' And VirtualServerName='" &_
         objQueueInst.VirtualServerName & "'")
      For each objMsgInst in objMsgsList
         strMsgInfo = strMsgInfo & "  Message " & _
            objMsgInst.MessageID & VbCrLF & _
            "    Sender: " & objMsgInst.Sender & VbCrLF &_
            "    MessageID: " & objMsgInst.MessageId & VbCrLF
      Next
   End If
Next

Wscript.Echo strMsgInfo 

This code has been viewed 1082 times.

New from the creators of TechTasks.com: StatSheet.com