BizTalk DevOps: Monitor your BizTalk environment using PowerShell –Monitoring Ports (Stopped/disabled/unelisted) with Auto-Healing capabilities

  • Sandro Pereira
  • Feb 15, 2016
  • 6 min read

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.

BizTalk Ports Status Report

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. 

Thanks for Buying me a coffe
Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

5 thoughts on “BizTalk DevOps: Monitor your BizTalk environment using PowerShell –Monitoring Ports (Stopped/disabled/unelisted) with Auto-Healing capabilities”

  1. 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

  2. Unable to download powershell script form microsoft site, Can you please upload in github and share with us

Leave a Reply

Your email address will not be published. Required fields are marked *

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top