Enumerate queues (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 SMTP links and queues on an
' Exchange Virtual Server and only works on Exchange Server 2003.

' ------ SCRIPT CONFIGURATION -----
' host name of the Exchange server
strHostname = "<ExchangeServerName>"
' e.g., red-exch02 ' The number of the SMTP virtual server instance
strVSInstance = "<VSInstanceNumber>"' e.g., 1 for the default SMTP virtual server
' ------ END CONFIGURATION --------

' Get the Exchange Namespace WMI object
Set objWMIExch =  GetObject("winmgmts://./root/MicrosoftExchangeV2")
' Get the list of Exchange_SMTPLink instances from the default virtual server
' and iterate through them.
Set objLinksList = objWMIExch.ExecQuery ("Select * from Exchange_SMTPLink" &_
   " Where VirtualMachine='" & strHostname &_
   "' And VirtualServerName='" & strVSInstance & "'")
For each objLinkInst in objLinksList
   strLinkInfo = strLinkInfo & "Link Name: " &_
      objLinkInst.LinkName & VbCrLF & "  Link ID: " &_
      objLinkInst.LinkID & VbCrLF
   ' Now, get the associated Exchange_SMTPQueue instances and iterate through
   ' them.
   Set objQueuesList = objWMIExch.ExecQuery ("Select * from Exchange_SMTPQueue" &_
      " Where VirtualMachine='" & strHostname &_
      "' And VirtualServerName='" & strVSInstance &_
      "' And LinkID='" & objLinkInst.LinkID &_
      "' And LinkName='" & objLinkInst.LinkName & "'" )
   For each objQueueInst in objQueuesList
      strLinkInfo = strLinkInfo & "  Queue Name: " &_
         objQueueInst.QueueName & VbCrLF & "    Queue ID: " &_
         objQueueInst.QueueID & VbCrLF
   Next
   strLinkInfo = strLinkInfo & VbCrLF
Next

Wscript.Echo strLinkInfo

This code has been viewed 1232 times.

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