In the sequence of my last post, welcome back, once again, to this series of articles about monitoring As a follow‑up to my previous post, welcome back to this series on monitoring BizTalk environments using PowerShell.
In this article, I revisit a topic previously covered by Jeroen, Monitor your BizTalk environment using PowerShell – Port monitoring. This time, however, I extend the script by adding auto‑healing capabilities.
Note: These scripts complement existing monitoring tools and work especially well when those tools are unavailable.
Monitoring the health of a BizTalk environment is one of the main responsibilities of BizTalk administrators. Administrators usually rely on tools such as the BizTalk Administration Console, BizTalk360, or SCOM. Unfortunately, these tools are not always available, yet the need to monitor and react remains.
As a follow‑up to my previous post, welcome back to this series on monitoring BizTalk environments using PowerShell.
In this article, I revisit a topic previously covered by Jeroen, Monitor your BizTalk environment using PowerShell – Port monitoring. This time, however, I extend the script by adding auto‑healing capabilities.
Note: These scripts complement existing monitoring tools and work especially well when those tools are unavailable.
Monitoring the health of a BizTalk environment is one of the main responsibilities of BizTalk administrators. Administrators usually rely on tools such as the BizTalk Administration Console, BizTalk360, or SCOM. Unfortunately, these tools are not always available, yet the need to monitor and react remains.
Many things can go wrong in a BizTalk environment. When issues persist, they quickly increase the business impact. For that reason, notifications alone are not enough. Manual intervention slows recovery and increases risk.
Instead, whenever possible, we should automatically recover affected artifacts. This approach allows receive locations and send ports to return to their expected state—enabled, started, or resumed—without human intervention.
📝 One-Minute Brief
Monitor and auto‑heal stopped, disabled, or unenlisted BizTalk ports using PowerShell scripts and proactive alerts.
So how can PowerShell help us?
With this script, you can monitor your BizTalk environment for disabled receive locations and stopped or unenlisted send ports, and automatically resume them according to certain conditions, using PowerShell.
A mail notification will be sent only if this scripts find any receive location or send port in a non-conform situation.
This sample will demonstrate how you can easily create a script with a set of conditions to be able to monitor and to automatically fix the receive locations and send ports to the desired state:
- “Enable” for receive locations.
- “Started” for send ports.
This script allows you to set:
- Set your email notification settings:
##Set mail variables
[STRING]$PSEmailServer = "mySMTPServer" #SMTP Server.
[ST RING]$SubjectPrefix = "Port status - "
[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 Counters: Check if there are any disable receive locations and stopped/unelisted send ports
if ($sendports.count -ne (get-wmiobject MSBTS_SendPort -namespace 'root\MicrosoftBizTalkServer' -filter '(Status = 3)').count)
{
[BOOL]$script:Continuescript = $True
[INT]$countSendPorts = $sendports.count - $(get-wmiobject MSBTS_SendPort -namespace 'root\MicrosoftBizTalkServer' -filter {Status = 3}).count
}
if ($ReceiveLocations.count -ne (get-wmiobject MSBTS_ReceiveLocation -namespace 'root\MicrosoftBizTalkServer' -filter '(IsDisabled = False)').count)
{
[BOOL]$script:Continuescript = $True
[INT]$countReceivePorts = $ReceiveLocations.count - $(get-wmiobject MSBTS_ReceiveLocation -namespace 'root\MicrosoftBizTalkServer' -filter '(IsDisabled = False)').count
}
if($countSendPorts -gt 0)
{
$mailTextReportPT += "" + $countSendPorts + " send ports stopped; "
$mailBodyPT += "<h3>Send ports Stopped</h3>"
#Add mail content for stopped send ports
Foreach ($SendPort in $SendPorts)
{
#only add stopped send ports to the mail
if ($SendPort.status -eq 2 -OR $SendPort.status -eq 1)
{
$StoppedSendPort = $True
#Set status to a user friendly name
if ($SendPort.status -eq 2)
{
$SendPortStatus = "Stopped"
}
elseif ($SendPort.status -eq 1)
{
$SendPortStatus = "Unelisted"
}
#Add mail content
$mailBodyPT += "<th><b><font color='red'>" + $SendPort.name + "</font></b></th>"
$mailBodyPT += "<table style='boder:0px 0px 0px 0px;'>"
$mailBodyPT += "<TR style='background-color:white;'><TD>Status</TD>"
$mailBodyPT += "<TD><b><font color='red'>" + $SendPortStatus + "</font><b></TD></TR>"
$mailBodyPT += "<TR style='background-color:rgb(245,245,245);';><TD>URI</TD>"
$mailBodyPT += "<TD>" + $SendPort.PTAddress + "</TD></TR>"
$mailBodyPT += "<TR style='background-color:white;'><TD>Transport type</TD>"
$mailBodyPT += "<TD>" + $SendPort.PTTransportType + "</TD></TR>"
if ($SendPort.status -eq 2)
{
#Auto-Healing feature
$SendPort.InvokeMethod("Start",$null)
$mailBodyPT += "<TR style='background-color:rgb(245,245,245);';><TD><font color='green'>Note</font></TD>"
$mailBodyPT += "<TD><font color='green'>The Stopped port was automatically Started by this script! Please access the environment to check if ports are running correctly.</font></TD></TR>"
}
$mailBodyPT += "</table>"
$mailBodyPT += "<BR><BR>"
}
}
}
if($countReceivePorts -gt 0)
{
$mailTextReportPT += "" + $countReceivePorts + " receive locations disabled; "
$mailBodyPT += "<h3>Receive locations Disabled</h3>"
#Add mail content for stopped receive locations
Foreach ($ReceiveLocation in $ReceiveLocations)
{
#only add stopped receive locations to the mail
if ($ReceiveLocation.IsDisabled -eq "True")
{
$StoppedReceiveLocation = $True
#Set status to a user friendly name
$ReceiveLocationStatus = "Disabled"
#Add mail content
$mailBodyPT += "<th><b><font color='red'>" + $ReceiveLocation.name + "</font></b></th>"
$mailBodyPT += "<table style='boder:0px 0px 0px 0px;'>"
$mailBodyPT += "<TR style='background-color:white;'><TD>Status</TD>"
$mailBodyPT += "<TD><b><font color='red'>" + $ReceiveLocationStatus + "</font></b></TD></TR>"
$mailBodyPT += "<TR style='background-color:rgb(245,245,245);';><TD>URI</TD>"
$mailBodyPT += "<TD>" + $ReceiveLocation.InboundTransportURL + "</TD></TR>"
$mailBodyPT += "<TR style='background-color:white;'><TD>Transport type</TD>"
$mailBodyPT += "<TD>" + $ReceiveLocation.AdapterName + "</TD></TR>"
#Auto-Healing feature
$ReceiveLocation.InvokeMethod("Enable",$null)
$mailBodyPT += "<TR style='background-color:rgb(245,245,245);';><TD><font color='green'>Note</font></TD>"
$mailBodyPT += "<TD><font color='green'>The Disabled port was automatically Enable by this script! Please access the environment to check if ports are running correctly.</font></TD></TR>"
Note: The script should be adjusted to your needs. Maybe having a variable or a list of receive location and Send ports that should be excluded for the monitoring or have a different expected status.
Here is an example expected report output from running the Windows PowerShell script sample, if any of the ports are in an unwanted state.

Again, this type of script must be viewed as a complement to the tools mentioned above, or used in their absence.
Download
THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.
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.
Hi Sandro,
this script does not seem to work with BizTalk Server 2016. I can’t get the receivelocations to start/ enable.
Do you know how this could be fixed?
Regards,
Adeel
Let me try it… it should work.
Where to pass the data base value.
Unable to download powershell script form microsoft site, Can you please upload in github and share with us
Hi Ravinder,
thanks for informing me about this issue. Indeed TechNet Gallery closed and I migrate everything for GitHub but I forgot to update this link. I already fixed the link and you can find the script here: https://github.com/sandroasp/BizTalk-Server-Resources/tree/master/PowerShell-scripts/Monitor-BTS-Stopped-Ports-with-Auto-Healing