biztalk receive location

How to restart a BizTalk Server Receive Location with PowerShell/BizTalk360

Long time since I played with PowerShell and BizTalk Server, but today I had a request from one of my clients who want to restart to SAP receive locations on a scheduled base. So, while helping them, I decided to publicly publish this resource so that others that face similar issues can also use it.

Restarting a receive location or a send port on a scheduled base is a common workaround to solve third-party adapter issues or even with out-of-the-box adapter issues like the SFTP adapter, especially in old BizTalk Server versions, or because of external systems/tools.

In our case, an SAP receive location is listening to a program id, and in some cases, randomly, we do not receive the messages, so we want to restart them on a fixed scheduling base to:

  • In one point to force the port to open/refresh the connectivity with SAP.
  • And in another point, to awake internal SAP stuff (resources, services, …)

This is something you can do by using BizTalk360 and many customers are actively using it, but that doesn’t mean that you cannot use this PowerShell script. Actually, BizTalk360 allows you to extend its out-of-the-box capabilities by allowing you to integrate PowerShell scripts with BizTalk360.

Of course, to use this script on a scheduled base, you need to use it inside BizTalk360 or you can create a Task Scheduler on the BizTalk Server machine or any other machine with access to BizTalk Server.

PowerShell to Restart a BizTalk Server Receive Location

With this script, we can accomplish exactly that: Restart a receive location by using PowerShell.

The function below accepts the receive location name and guarantees that a “restart” is made. In reality, there isn’t a restart operation, instead, we need to stop it (Disable), and then when it is successfully stopped we will start it (Enable). 

function restart-receive-location (
    [string]$receiveLocation)
{
    # Get the Receive Location by name
    $location = get-wmiobject msbts_receivelocation -Namespace 'root\MicrosoftBizTalkServer' -Filter "name='$receiveLocation'"

    #Disable the receive location (stop)
    $location.Disable()

    #Loop to check and garanty that the receive location was successfully disables (stopped)
    #Sometimes this can take a few seconds depending the workload that BizTalk Server is processing
    #So this loop is here to security to garanty the enable operation will be trigger only when the port is disabled.
    Do
    {

        $location = get-wmiobject msbts_receivelocation -Namespace 'root\MicrosoftBizTalkServer' -Filter "name='$receiveLocation'"
        if($location.IsDisabled -eq $false) {
            Start-Sleep -s 10
        }

    } While ($location.IsDisabled –eq $false)

    #Enable the receive location (Start)
    $location.Enable()
}
 
THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.

Download

You can download How to restart a BizTalk Server Receive Location with PowerShell from GitHub here:

Use BizTalk360 to restart a Receive Location

At the time of writing, the BizTalk360 team is working on v10.3. An important feature of that release will be the Automated Task feature. This will allow you to stop/start/restart ports, orchestrations, host instances, and logic apps on a scheduled basis.

See below, a couple of screenshots of the feature. Be aware, that the feature has not been released, so the screenshots are subject to change.

restart a Receive Location
biztalk receive location

So, if you have BizTalk360, you won’t need to create PowerShell and the Windows Task Scheduler to start/stop/restart those components. All you have to do is to wait for v10.3 to be released.