4

In BizTalk Server Administration Console you can query for suspended service instances and then filter them by Application Name. I need such functionality without BTS Administration Console.

So far I've created Powershell script to get suspended instances:

$array = Get-WmiObject MSBTS_ServiceInstance `
           -Namespace 'root\MicrosoftBizTalkServer' `
           -Filter '(ServiceClass = 4 or ServiceClass = 1) `
                 and (ServiceStatus = 4 or ServiceStatus = 16)' 
foreach ($element in $array)
{
    Write-Host $element.InstanceID "-" $element.HostName "-" `
                 $element.ServiceStatus "-" $element.ServiceClass
}

If you run this script you'll get all suspended instances, but how to find out to what application they belong?

Any solution that uses PowerShell, WMI or C# is good for me.

SteveC
  • 15,808
  • 23
  • 102
  • 173
Ash
  • 1,924
  • 1
  • 13
  • 14

3 Answers3

2

I've used the Microsoft.BizTalk.Operations assembly ...

Add-Type -AssemblyName ('Microsoft.BizTalk.Operations, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL')
$dbServer = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\BizTalk Server\3.0\Administration' 'MgmtDBServer').MgmtDBServer
$dbName = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\BizTalk Server\3.0\Administration' 'MgmtDBName').MgmtDBName
$bo = New-Object Microsoft.BizTalk.Operations.BizTalkOperations $dbServer, $dbName
$serviceInstances = $bo.GetServiceInstances()

$tgt = "DeploymentFramework.Samples.HelloWorld"
foreach ($instance in $serviceInstances)
{
    if ($instance.Application -ieq $tgt)
    {
        $completionStatus= $bo.TerminateInstance($instance.Id)
    }
}

One thing I've not worked out ... Why does terminating a suspended (not resumable) service instance return Failed, yet it is terminated

Community
  • 1
  • 1
SteveC
  • 15,808
  • 23
  • 102
  • 173
  • Just my 2 cents: before this answer i have created custom MSBuIld task that used WMI to find application and suspended messages - the only issue was that I was not able to terminate them in batch so it took a lot of time to terminate them one by one in loop – Ash May 12 '16 at 12:03
1

What version of BizTalk?

This works on BizTalk 2010:

$array = Get-WmiObject MSBTS_ServiceInstance `
           -Namespace 'root\MicrosoftBizTalkServer' `
           -Filter '(ServiceClass = 4 or ServiceClass = 1) ` 
                 and (ServiceStatus = 4 or ServiceStatus = 16)' 
foreach ($element in $array)
{
    Write-Host $element.ServiceName
}
SteveC
  • 15,808
  • 23
  • 102
  • 173
1

Application name property is not exposed via MSBTS_ServiceInstance class. I believe the reason for that is, application concept was only introduced in BizTalk 2006 but the WMI API was present right from 2004.

I'm afraid, your only choice is to go directly to the database.

Saravana Kumar
  • 596
  • 3
  • 8