Freigeben über


Saving Suspended Messages using WMI, PowerShell and the Microsoft.BizTalk.Operations Assembly (Part II)

In Part I of this article, we discussed about saving suspended messages using WMI and a fairly simple PowerShell script. The problem with that approach is that it works great as long as your suspended orchestration instances don’t contain multiple suspended messages. If your suspended orchestration instances have more than a
single message, the script above only retrieves one of the messages. This behavior may change with the rollout of a BizTalk hotfix. But, until then, the workaround is to use a different approach.

For this solution, we used a .NET assembly that does most of the heavy lifting. The methods exposed by this assembly were then called from the PowerShell script we used in Part I of this sample (with a minor tweak). You need to add references to the following assemblies in the .NET class - Microsoft.BizTalk.Operations, Microsoft.BizTalk.Pipeline (both should be available in the GAC on a machine that has BizTalk installed).

The trick used here is that the WMI caller script supplies the suspended instances one-by-one to the .NET assembly, which in turn spits out all the suspended messages for that instance. In this solution, you get all the suspended messages for a service instance, and not just a single message you get in a purely WMI solution.

Usage : To use this script, save the .ps script and the helper .NET assembly (say at the path - C:\script\Save_Suspended_msgs.ps1 ), and run this from the PowerShell command prompt:

PS C:\Users\Administrator> C:\script\Save_Suspended_msgs.ps1 -action save "c:\temp\Suspended_msgs"

And lo and behold, your messages appear in the folder that you provided in the command window!


This would create separate folders for each suspended instance type under the ‘Suspended_msgs’folder specified above. So, if you have suspended instances for two different Orchestration types, it would create folders named after those Orchestrations and save out the messages in their respective folders.
I am providing the script folder I used for testing this (contains the .NET assembly and the PowerShell script). Also, if you want to look into the .NET helper class, I am providing the .NET Visual Studio solution as well (built on VS 2010).

Have fun !

Written By
Arindam Paul Roy

Reviewed By
Chirag Pavecha

Microsoft India GTSC

 

Script and PSLib.zip

Comments

  • Anonymous
    February 10, 2014
    Thanks for the great script. It works very well in most cases, however I can't seem to save messages with a routing failure. Do you know if this is just not possible or is there a way I can make this work? Saving out message with ID 4eb61ac5-5eec-47f4-bf4d-2e1be1ba54b8 ...Exception calling "getMessageswithOPS" with "2" argument(s): "The specified message is a routing failure report and cannot be saved."At D:SaveAllSuspendedMessagesSave_Suspended_msgs.ps1:57 char:51    %{ $counter++; [Test.Program]::getMessagesWithOPS <<<< ($.InstanceID , $path + "&quot; + $.ServiceName) }   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException   + FullyQualifiedErrorId : DotNetMethodException

  • Anonymous
    March 06, 2014
    Hi,A routing failure message is just a report with a bunch of context properties, so there's "no message" to be saved there. The actual message that generated the routing failure report would still be available as a Suspended (Resumable). The script should save that out.Also, you may want to filter out RFRs so that the script does not even attempt to save them - see Part I of the article - the code for RFRs is available on it. Just add a filter to thebts-get-messaging-svc-instances() method in the script so that you're not attempting to save RFRs.

  • Anonymous
    January 28, 2015
    It seems that this script cannot save more than 50 messages - then it stops - or am I missing somthing?I can't get it to return more even though BSAC shows way more than 50 suspended.

  • Anonymous
    February 19, 2015
    Will this satisfy for non-resumable also??

  • Anonymous
    November 06, 2015
    Hi Bo, It is possible to save more messages than 50.

    • Anonymous
      July 21, 2016
      what are the changes to save more than 50 messages. script is not saving more than 50 for one instance.