Close

Suspended instances via Powershell

Hieronder is een script voor het ophalen en opslaan van suspended instances. Het is handig om de beschikbare BizTalk WMI objects te kennen. Zie link: http://msdn.microsoft.com/en-us/library/aa560069.aspx # Aanroep list suspended instances: .bts-get-suspended-msgs -action list # Save messages suspended instances: .bts-get-suspended-msgs -action save ‘c:paulsuspendedmsg’ Ik heb geprobeerd om specifieke contextproperties op te halen, bijvoorbeeld InboundTransportLocation. Volgens mij is dat niet mogelijk. Vond in een blog post de volgende melding: “a single property within the context will not be possible since the whole context is just stored or exposed as a single xml string”. # # declare our parameters: the action to take, and an optional # path to save messages to # param( [string] $action=$(throw ‘need action’), [string] $path=$(if (($action -eq ‘save’) -or ($action -eq ‘context’)) { throw ‘need path’ }) ) # # get all suspended messaging service instances, # both resumable and not-resumable # function bts-get-messaging-svc-instances() { # ServiceClass = 1 – Orchestration # ServiceClass = 2 – Tracking # ServiceClass = 4 – Messaging # ServiceClass = 8 – MSMQT # ServiceClass = 16 – Other # ServiceClass = 32 – Isolated adapter # ServiceClass = 64 – Routing failure report # ServiceStatus = 1 – Ready To Run # ServiceStatus = 2 – Active # ServiceStatus = 4 – Suspended (Resumable) # ServiceStatus = 8 – Dehydrated # ServiceStatus = 16 – Completed With Discarded Messages’ in BizTalk Server 2004 # ServiceStatus = 32 – Suspended (Not Resumable) # ServiceStatus = 64 – In Breakpoint get-wmiobject MSBTS_ServiceInstance ` -namespace ‘rootMicrosoftBizTalkServer’ ` -filter ‘ServiceClass=4 and (ServiceStatus = 4 or ServiceStatus = 16)’ } # # save the message associated to the # specified messaging Service Instance # function bts-save-message([string]$msgid) { $msg = get-wmiobject MSBTS_MessageInstance ` -namespace ‘rootMicrosoftBizTalkServer’ ` -filter “ServiceInstanceID = ‘$msgid'” $msg.psbase.invokemethod(‘SaveToFile’, ($path)) “Message from ServiceInstanceID=$msgid saved.” } # # save the message associated to the # specified messaging Service Instance # function bts-save-messagecontext([string]$msgid) { $msg = get-wmiobject MSBTS_MessageInstance ` -namespace ‘rootMicrosoftBizTalkServer’ ` -filter “ServiceInstanceID = ‘$msgid'” $context = $msg.Context Write-Host $context “Message context from ServiceInstanceID=$msgid saved.” } # # main script # Aanroep list suspended instances: .bts-get-suspended-msgs -action list # Save messages suspended instances: .bts-get-suspended-msgs -action save ‘c:paulsuspendedmsg’ # switch ( $action ) { ‘list’ { bts-get-messaging-svc-instances | fl InstanceId, ServiceName, SuspendTime, HostName, ServiceStatus, ErrorId, ErrorDescription } ‘save’ { bts-get-messaging-svc-instances | %{ bts-save-message($_.InstanceID) } } ‘context'{ bts-get-messaging-svc-instances | %{ bts-save-messagecontext($_.InstanceID) } | } } Tip: Er is ook een WMI Code Creator tool (gratis download) waarmee je C# kunt genereren met WMI queries. Kreeg het nog niet voor elkaar, maar is het proberen waard. Al zoekend kwam ik ook een WMI browser & PowerShell code generator tegen, genaamd de PowerShell WMI Explorer. Een paar ideeën om hier verder mee te komen. Voorbeeld gegenereerd VBScript van de WMI Code Creator. De context van messages achterhalen. Code kun je runnen vanuit de WMI Code Creator tool. strComputer = “.” Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootMicrosoftBizTalkServer”) Set colItems = objWMIService.ExecQuery( _ “SELECT * FROM MSBTS_MessageInstance”,,48) For Each objItem in colItems Wscript.Echo “———————————–” Wscript.Echo “MSBTS_MessageInstance instance” Wscript.Echo “———————————–” Wscript.Echo “Context: ” & objItem.Context Next