How to determine the process ID of BizTalk Host Instances with PowerShell

Posted: May 3, 2012 in BizTalk
Tags: , , ,

In two of my previous posts I introduced and explained how to debug BizTalk components in Visual Studio: BizTalk – How to debug Custom Pipeline Components running on Isolated Host and Debugging External assembly’s or pipeline components – Attach to Process – which BizTalk process to use?.

In the last one, I presented two ways of how we could determine the process id of BizTalk Host Instances:

  • Using Tasklist command. This command displays a list of applications and services with their Process ID (PID) for all tasks running on either a local or a remote computer.
  • Using C# code

Now I will present how we can accomplish this using PowerShell:

$machineName = hostname
$query = "root\MicrosoftBizTalkServer", "Select * from MSBTS_HostInstance where HostType = 1 and ServiceState = 4 and RunningServer = '$machineName'"
$hostInstanceSearch = new-object system.management.managementObjectsearcher($query)

$hostInstanceList = $hostInstanceSearch.get()

foreach ($hostInstanceItem in $hostInstanceList)
{
   $processName = $hostInstanceItem.HostName
   $perfCounter = New-Object System.Diagnostics.PerformanceCounter("BizTalk:Messaging", "ID Process", $processName)
   $processID  = $perfCounter.NextValue()

   Write-Host
   Write-Host "HostName: " -foregroundcolor yellow -NoNewLine
   Write-Host $hostInstanceItem.HostName -foregroundcolor white
   Write-Host "Process Id: " -foregroundcolor yellow -NoNewLine
   Write-Host $processID   -foregroundcolor white
   Write-Host
}

Determining the process ID of BizTalk Host Instances (0.89 KB)
Microsoft | TechNet Gallery

Comments
  1. Amit says:

    there is another way to figure out the PIDs for BizTalk host.

    If you have a 32 bit hosts then run the following:
    tasklist /SVC /fi “imagename eq btsntsvc.exe”

    and if you have 64 bit hosts then run this:
    tasklist /SVC /fi “imagename eq btsntsvc64.exe”

    the /fi is a filter and the eq is equals.

  2. […] determine which process id is causing the trouble. You can find this piece of PowerShell also in a post from Sandro. For completeness sake I’ll show it […]

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