As a continuation of my previous two posts, welcome back to this series on monitoring BizTalk environments using PowerShell. This article is probably the last one in the series for now.
Today, I introduce a new topic: monitoring BizTalk Host Instances using PowerShell. As with the previous articles, I also extend the script by adding auto‑healing capabilities.
Monitoring the health of a BizTalk environment is a core responsibility for BizTalk administrators. Administrators typically rely on tools such as the BizTalk Administration Console, BizTalk360, SCOM, and similar solutions. However, these tools are not always available, and administrators still need an effective way to monitor and react to issues.
Many things can go wrong in a BizTalk environment. When problems persist, they quickly increase the business impact. For that reason, notifications alone are not enough. Relying only on manual intervention slows recovery and increases risk.
Instead, whenever possible, we should automatically recover affected artifacts. This approach allows host instances to return to their desired state—started, resumed, or enabled, depending on the scenario.
Note: These scripts are intended to complement existing monitoring tools or to act as an alternative when those tools are unavailable.
📝 One-Minute Brief
One-Minute Brief (TL;DR):
So how can PowerShell help us?
With this script, you can monitor your BizTalk environment for Host Instances that aren’t started (Stopped, start pending, stop pending, continue pending, pause pending, Paused, or Unknown), and automatically bring them to the desired state (Started) according to certain conditions, using PowerShell.
Only if the script finds any suspended messages will a mail notification be sent.
This script allows you to set:
- Set your email notification settings:
#Set mail variables
[STRING]$PSEmailServer = "mySMTPServer"
#SMTP Server.
[STRING]$SubjectPrefix = "Host instances not running - "
[STRING]$From = "biztalksupport@mail.pt"
$EmailTo = ("sandro.pereira@devscope.net")
The following Windows PowerShell script is a fragment that will help us demonstrate these capabilities:
# Get Host instances not running
[ARRAY]$hostInstances = get-wmiobject MSBTS_HostInstance -namespace 'root\MicrosoftBizTalkServer' -filter '(HostType = 1 and ServiceState != 4)'
foreach ($hostInstance in $hostInstances)
{
#Add mail content
$mailBodyHI += "<th><b><font color='blue'>" + $hostInstance.Name + "</font></b></th>"
$mailBodyHI += "<table style='boder:0px 0px 0px 0px;'>"
$mailBodyHI += "<TR style='background-color:white;'><TD>Host Name</TD>"
$mailBodyHI += "<TD><b><font color='red'>" + $hostInstance.HostName + "</font></b></TD>
</TR>"
$mailBodyHI += "<TR style='background-color:rgb(245,245,245);';><TD>Host Type</TD>"
$mailBodyHI += "<TD>In-process</TD></TR>"
$mailBodyHI += "<TR style='background-color:white;'><TD>Running Server</TD>"
$mailBodyHI += "<TD><b><font color='red'>" + $hostInstance.RunningServer + "</font></b></TD></TR>"
# Stopped: 1
# Start pending: 2
# Stop pending: 3
# Running: 4
# Continue pending: 5
# Pause pending: 6
# Paused: 7
# Unknown: 8
if ($hostInstance.ServiceState -eq 1)
{
$statusHI = "Stopped"
}
if ($hostInstance.ServiceState -eq 2)
{
$statusHI = "Start pending"
}
if ($hostInstance.ServiceState -eq 3)
{
$statusHI = "Stop pending"
}
if ($hostInstance.ServiceState -eq 5)
{
$statusHI = "Continue pending"
}
if ($hostInstance.ServiceState -eq 6)
{
$statusHI = "Pause pending"
}
if ($hostInstance.ServiceState -eq 7)
{
$statusHI = "Paused"
}
if ($hostInstance.ServiceState -eq 8)
{
$statusHI = "Unknown"
}
$mailBodyHI += "<TR style='background-color:rgb(245,245,245);';><TD>Service State</TD>"
$mailBodyHI += "<TD><b><font color='red'>" + $statusHI + "</font></b></TD></TR>"
#0: UnClusteredInstance
#1: ClusteredInstance
#2: ClusteredVirtualInstance
if ($hostInstance.ClusterInstanceType -eq 0)
{
$statusHI = "UnClustered Instance"
}
if ($hostInstance.ClusterInstanceType -eq 1)
{
$statusHI = "Clustered Instance"
}
if ($hostInstance.ClusterInstanceType -eq 2)
{
$statusHI = "Clustered Virtual Instance"
}
$mailBodyHI += "<TR style='background-color:white;'><TD>Cluster Instance Type</TD>"
$mailBodyHI += "<TD>" + $statusHI + "</TD></TR>"
$mailBodyHI += "<TR style='background-color:rgb(245,245,245);';><TD>Is Disabled</TD>"
$mailBodyHI += "<TD>" + $hostInstance.IsDisabled + "</TD></TR>"
$mailBodyHI += "<TR style='background-color:white;'><TD>NT Group Name</TD>"
$mailBodyHI += "<TD>" + $hostInstance.NTGroupName + "</TD></TR>"
$mailBodyHI += "<TR style='background-color:rgb(245,245,245);';><TD>Logon</TD>"
$mailBodyHI += "<TD>" + $hostInstance.Logon + "</TD></TR>"
#Auto-Healing feature
if($hostInstance.IsDisabled = "False")
{
$hostInstance.InvokeMethod("Start",$null)
$mailBodyHI += "<TR style='background-color:white;'><TD><font color='green'>Note</font></TD>"
$mailBodyHI += "<TD><font color='green'>The Host Instance was started automatically by this script! Please access the environment to validate if all host instances are running.</font></TD></TR>"
}
$mailBodyHI += "</table>"
$mailBodyHI += "<BR><BR>"
}
Here is an example expected report output from running the Windows PowerShell script sample, if any of the Host Instances are in an unwanted state.

Note: This type of script must be viewed as a complement to the tools mentioned above or used in the absence of them. The script should also be adjusted to your needs.
Download
THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.
You can download Monitoring BizTalk Host Instance with Auto-Healing with PowerShell from GitHub here:
Hope you find this helpful! If you liked the content or found it useful and would like to support me in writing more, consider buying (or helping to buy) a Star Wars Lego set for my son.