Recipe 7.12. Listing the SMTP Queues on a Specific Virtual ServerProblemYou need to list the SMTP queues associated with a specific virtual server instance on your Exchange server. SolutionUsing a graphical user interface
Using VBScript' 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 DiscussionTo get a good understanding of traffic flow through Exchange, you need to understand queues and links. Each Exchange SMTP virtual server (or X.400 stack for the MTA transport) has its own set of queues, which are a set of folders on an NTFS partition. Each queue holds messages destined for a single DNS domain; messages addressed to recipients in the 3sharp.com and redmond.3sharp.com domains are placed in two different queues. Links are virtual memory structures that represent the next system a message must be sent to. Each link is associated with zero or more queues. While it may sound odd that links can have no queues, not all links are transient in an Exchange organization; routing group connectors and smart hosts provide dedicated links to next-hop systems and the links to them exist even when there is no traffic to route through them. Conversely, a link can have more than one associated queue, such as when the remote server is published in DNS as the MX host for multiple domains. Tracking links and queues through the Exchange System Manager Queue Viewer can be somewhat confusing; what ESM calls queues are actually links. It uses the Queue API to provide a unified management interface for the links and queues on the server, presenting them without distinguishing precisely what is a link and what is a queue. WMI always makes the difference explicit. There are a default set of SMTP system queues and links that are always present. They are shown in Table 7-3 along with their corresponding WMI properties and ESM queue names.
To get an accurate view of the queues and links, you need to use WMI scripting. Exchange 2000 provides two classes through the ExchangeQueueProvider provider; these classes, ExchangeLink and ExchangeQueue, provide read-only access to the status of all links and queues on the server. Exchange Server 2003 supplies additional WMI providers and classes that allow you to easily choose between SMTP and X.400 queues and links and manage them. These new classes are shown in Table 7-4.
For day-to-day management and monitoring of the SMTP queues, you will only need to deal with the Exchange_SMTPLink and Exchange_SMTPQueue classes. As demonstrated by the script above, using these classes together to obtain queue information is not difficult. A simple WMI Query Language (WQL) query, constrained by the physical server name and (if desired) virtual server instance, enumerates your existing links. You can then pull the LinkID and LinkName properties to use as a constraint against a second WQL query for the associated queues. See AlsoMSDN: Exchange_Link, MSDN: Exchange_Queue, MSDN: Exchange_SMTPLink, MSDN: Exchange_SMTPQueue, MSDN: Exchange_X400Link, MSDN: Exchange_X400Queue, Recipe 7.13 for listing messages in a queue, and Recipe 7.14 for deleting messages from a queue |