Querying the WMI MSBTS_MessageInstance class

As I suppose not everyone reading my blog is reading the newsgroups on a daily basis, here's a highlight. Today, a question came up regarding the querying of the MSBTS_MessageInstance class.

Let's summarise what is possible with this WMI class:

Retreiving all message instances that are currently available in the message box.

Retreiving all message instances that comply with certain conditions and are currently available in the message box.

Saving any of those messages to the file system.

What is not possible with this class?

Saving or retreiving a message that is tracked. Tracked messages are not handled in the same way as messages that are still resided in the message box. If you want to save tracked message instances, you need to use the MSBTS_TrackedMessageInstance WMI class. Please keep in mind, when doing this, that this class does *not* support enumeration. You will need to use the MessageInstanceID in order to create an instance of it!

In addition, remember that it is not possible to use the MSBTS_MessageInstance class to make select queries based upon the content of the message context! Why? Message context is something dynamic and is not compiled into the WMI classes. The message context is accessible on the class as an XML string though... Making selects is only possible using the WMI properties on this class. Like: ServiceName, ServiceInstanceStatus, ServiceInstanceID, ServiceClassId, ServiceClass...

this is true. You need to retreive the message first and then retreive it's context. That context is only available as an XML String so querying it directly is not possible. (This would have required BizTalk Server to dynamically compile WMI classes - *that* would be funky!)