Managing Mail Messages
Now that you know how to retrieve information about and manage queues and links, you can manage mail messages. Before you can manage a mail message, you have to locate it. You can again use GetCollectionOfInstances.wsf, but this time you need to specify the Exchange_QueuedSMTPMessage class in the WQL query. However, WMI doesn't let you query all instances of the Exchange_QueuedSMTPMessage class that you might have across the various queues. You must specify the queue and link that contains the message. The WMI properties you need to include are the Exchange_SMTPQueue class's LinkID, LinkName, ProtocolName, QueueID, and QueueName properties. Fortunately, getting these properties' values is easy. You can simply run GetCollectionOfInstances.wsf against a WQL query that specifies the Exchange_SMTPQueue class, as I did to obtain the SMTP queue information in Web Figure 1. Figure 4 shows a sample WQL query that retrieves a mail message. Web Figure 4 contains the output from this query.
After you locate the message, you can use the Exchange_QueuedSMTPMessage class's methods to manage that message. The four methods and the corresponding options in ESM are as follows:
- The DeleteNDR method, which corresponds to ESM's Delete (with NDR) option, deletes a message and sends a nondelivery report (NDR).
- The DeleteNoNDR method, which corresponds to ESM's Delete (no NDR) option, deletes a message but doesn't send an NDR.
- The Freeze method, which corresponds to ESM's Freeze option, stops a message from leaving the queue.
- The Thaw method, which corresponds to ESM's Unfreeze option, releases a message that was previously stopped.
In ESM, you can find the options just listed by clicking the Find Messages button, which leads to a dialog box that lets you search for messages. If you right-click a search result, the Properties dialog box provides the four options, as Web Figure 5 shows.
None of the Exchange_QueuedSMTPMessage class methods requires an input parameter. Thus, you can adapt LinkOps.wsf so that it deletes, freezes, or thaws messages. You just need to adapt this script by changing the WQL query at callout C and the name of the invoked method at callout D. The WQL query would be similar to the one in Figure 4.
Monitoring the Cache Refresh
To improve the queue subsystem information access, ExchangeQueue2Provider has a cache to store management data. ExchangeQueue2Provider automatically refreshes this cache, following a schedule that it determines based on the Exchange server's configuration and activity level. (You can't control the refresh schedule.) On my Exchange system, ExchangeQueue2Provider refreshes its cache about every 5 minutes.
The Exchange_QueueCacheReloadEvent class is useful for monitoring when ExchangeQueue2Provider refreshes its cache. If you run the script GenericEventAsyncConsumer.wsf, which I used in Part 1, against the WQL query
Select * From
Exchange_QueueCacheReloadEvent
you'll receive notifications each time ExchangeQueue2Provider refreshes its cache. Web Figure 6 shows the output from this query. Through these notifications, you can determine the refresh schedule of ExchangeQueue2Provider in your system.
Any information that ExchangeQueue2Provider returns through one of its supported classes is subject to the cache refresh. When submitting an event query to monitor a change on a queue or link instance, the submitted query uses the WITHIN statement to tell WMI to perform a polling. Because the ExchangeQueue2Provider updates its queue and link instances on a regular time frame depending on the cache updates, performing a monitoring with a polling frequency in the WQL event query that's inferior to the cache refresh timeout is useless because the provider won't reflect any change within the cache refresh timeout period.
Great Improvements
Exchange 2003's new ExchangeQueue2Provider and its set of supported classes let you manage queue- and link-related tasks the same way you manage them through ESM. The ability to duplicate UI operations though programmable interfaces is a great asset when you want to automate the management of a system. In this regard, Exchange 2003 offers some real improvements over its predecessors, as this series has demonstrated.