When you have many BizTalk host instances and you want to do a “Debug Attach” to one specific one (for example to debug a pipeline component), it really helps to know the process ID (else you might have to attach to many host instances).

The Powershell code below conveniently lists the process ids along with the host name.
Credit for this code goes to Randal van Sputeren’s blog:

## https://biztalkmessages.wordpress.com/2010/01/05/retrieve-the-btsntsvc-exe-pid-with-powershell/
## Requires the BizTalk add-ons for Powershell 

function GetHostPID
   Get-ChildItem -Path 'Biztalk:\Platform Settings\Host Instances' | ForEach-Object {

   if ($_.HostType -ne 'Isolated')
          [string]$a = (Get-WmiObject Win32_Process -filter "CommandLine Like '%$($_.HostName)%'").ProcessId
         $_ | Add-Member -MemberType NoteProperty -Name PID -Value $a
        Write-Output $_
   } | Format-Table PID, Name, HostName, NTGroupName, RunningServer, HostType, ServiceState

GetHostPID   #call the above function 

Example Output

Debug Attach

In Visual Studio, you can attach your code to one or many BizTalk Host Instances in order to debug a helper routine or pipeline component. If you have many host instances, it’s difficult to know which one to pick. The screen below doesn’t list the Host Instance Names, only the Process IDs. So you need the Powershell command above, to xref the Host Instance to the Process ID.

Tagged with:

Filed under: VisualStudio