PowerShell – Quick sample of getting a BizTalk Performance Counter information

As you all probably know, you can use the “Reliability and Performance Monitor” in older servers, or the “Performance Monitor” in newer ones.  This mean going thru the GUI to start setting up you user-defined custom counters.

Well, for a pointer, the GUI can help in fine-tuning what you want to accomplished in your script.  Here’s a quick example of getting a  “BizTalk:Message Agent” Performance counter to get the “Total messages published” for a giving application.  But before you start going crazy with BizTalk, make sure the application(s) are “Started“.

Note: To get Microsoft BizTalk Server Performance Counter information, here’s some links:

I have ran the following script code against all version of PowerShell V1->V3:

1. First you need to load the Assembly responsible of giving you the Performance Counter class:

 [System.Reflection.Assembly]::LoadWithPartialName(“System.Diagnostics”)

2. Then, we can create the PowerShell variable that will hold our results:

$bpc = new-object system.diagnostics.PerformanceCounter(“BizTalk:Message Agent“, “Total messages published“, “YourHostInstanceName”, “BTSserver”);

3. To display the information just type: $bpc.

Sample output:

PS D:\> $pbc

CategoryName     : BizTalk:Message Agent
CounterHelp      : The total number of messages published by the service class
CounterName      : Total messages published
CounterType      : NumberOfItems32
InstanceLifetime : Global
InstanceName     : BizTalkServerApplication
ReadOnly         : True
MachineName      : XXXXXXX
RawValue         : 71191
Site             :
Container        :

And, that’s it.

You’re looking for the “RawValue“.  To keep updating the result I notice you can call the variable again without running the two previous script lines.  Eventually, you can enhanced this sample to go thru each of BizTalk Server, each BizTalk host instances, and pull the information.

That’s Awesome!

I’m using BizTalk Performance Counter as an example but you can probably figures out how to use the other counters, and the rest I leave the rest to your imagination.