BizTalk Save Bulk Messages

The BizTalk 2006 Administration Console doesn’t provide bulk export functionality.  See below script using WMI.  I tweaked and cleaned up the terminate sample from MSDN to simply save to file without terminating.
 
‘ SaveBulk.vbs
dim objBtsWmiNS, objMsg, svcinsts, inst, msg, ndx, size
Dim aryClassIDs()
Dim aryTypeIDs()
Dim aryInstanceIDs()
Dim aryHostNames()
Dim aryObjQueues()
Dim aryHostBatchSize()
Dim strKey2Instance
Dim strQuery2Msg
On Error Resume Next
Dim objArgs: Set objArgs = WScript.Arguments
If ( objArgs.Count = 0 OR objArgs.Count > 2) Then
     wscript.quit 0
End If
wmiQuery = ""
‘ServiceStatus = 16 – ‘Completed With Discarded Messages’ in BizTalk Server 2004
‘ServiceStatus = 32 – ‘Suspended (not resumable)’
‘ServiceStatus = 4 – ‘Suspended (resumable)’
‘ServiceStatus = 8 – dehydrated
‘ServiceClass = 64 – ‘Routing Failure Report’
‘ErrorId = "0xC0C01B4C" – is how ‘Completed With Discarded Messages’ are exposed in BizTalk Server 2006
If (objArgs(0) = "-Z" OR objArgs(0) = "-z") Then
     wmiQuery = "select * from MSBTS_serviceinstance where ServiceStatus=16"
End If
If (objArgs(0) = "-DEH" OR objArgs(0) = "-deh") Then
     wmiQuery = "select * from MSBTS_serviceinstance where ServiceStatus=8"
End If
If (objArgs(0) = "-A" or objArgs(0) = "-a") Then
     wmiQuery = "select * from MSBTS_serviceinstance where ServiceStatus=4 OR ServiceStatus=32 OR ServiceStatus=16 OR ErrorId=’0xC0C01B4C’ OR ServiceClass=64"
End If
If (objArgs(0) = "-SR" or objArgs(0) = "-sr") Then
     wmiQuery = "select * from MSBTS_serviceinstance where ServiceStatus=4"
End If
If (objArgs(0) = "-SNR" or objArgs(0) = "-snr") Then
     wmiQuery = "select * from MSBTS_serviceinstance where ServiceStatus=32"
End If
If (objArgs(0) = "-DIS" or objArgs(0) = "-dis") Then
     wmiQuery = "select * from MSBTS_serviceinstance where ServiceClass=32 AND ServiceStatus=8"
‘ServiceClass = 32 ‘Isolated Adapter
‘ServiceStatus = 8 ‘Dehydrated
End If
saveMessagesBeforeTermination = True
If ( objArgs.Count > 1) Then
     If (objArgs(1) = "-NOSAVE" OR objArgs(1) = "-nosave") Then
          saveMessagesBeforeTermination = False
     Else
          PrintUsage()
          wscript.quit 0
     End If
End If
If(wmiQuery = "") Then
     PrintUsage()
     wscript.quit 0
End If
Set objBtsWmiNS = GetObject("WinMgmts:{impersonationLevel=impersonate, (security)}\\.\root\MicrosoftBizTalkServer")
If Err <> 0 Then
     CheckWMIError
     wscript.quit 0
End If       
Set hosts = objBtsWmiNS.ExecQuery("select * from MSBTS_HostSetting")
If Err <> 0 Then
     CheckWMIError
     wscript.quit 0
End If       
hostCount = hosts.count
ReDim aryHostNames(hostCount – 1)
ReDim aryObjQueues(hostCount – 1)
ReDim aryHostBatchSize(hostCount – 1)
ndx = 0
For Each host in hosts
     aryHostNames(ndx) = host.Properties_("Name")
     Set aryObjQueues(ndx) = objBtsWmiNS.Get("MSBTS_HostQueue.HostName=""" & aryHostNames(ndx) & """")
     If Err <> 0 Then
          CheckWMIError
          wscript.quit 0
     End If       
     ndx = ndx + 1
Next
Set svcinsts = objBtsWmiNS.ExecQuery(wmiQuery)
ReDim aryClassIDs(hostCount, maxBatchSize-1)
ReDim aryTypeIDs(hostCount, maxBatchSize-1)
ReDim aryInstanceIDs(hostCount, maxBatchSize-1)
‘Iterate through instances and save them in host-specific arrays.
totalCount = 0
For Each inst in svcinsts
     ‘Resolve host index
     For hostIdx = 0 To hostCount-1
          If aryHostNames(hostIdx) = inst.Properties_("HostName") Then
               Exit For
          End If
     Next
               strQuery2Msg = "select * from MSBTS_MessageInstance where ServiceInstanceID=""" & inst.Properties_("InstanceId") & """"
               Set msgInsts = objBtsWmiNS.ExecQuery(strQuery2Msg)
               For Each msg in msgInsts
                    msg.SaveToFile "C:\OUT\"     
              Next
          totalCount = totalCount + 1
Next

wscript.echo "SUCCESS> " & totalCount & " instances were found"
 
Technorati Tags:

Advertisements
This entry was posted in BizTalk Server. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s