This post was originally published here

Until now we have seen some default functionalities, except for the last sample, done in a different way and with small improvements with PowerShell:

  • How can we easily export a binding file from a BizTalk Application?
  • How can we easily export a binding file from a specify assembly?
    • Using the fully qualified name (FQName) of the assembly.
    • Using only the assembly name

From now on we will deep dive in this topic, addressing some useful unsupported scenarios, which are impossible to be addressed using the out-of-the-box tools BizTalk Server Administration Console or even with the BTSTask command-line tool included with BizTalk Server.

  • How can we easily export a binding file from a list of assemblies?
  • How can we easily export a binding file from a Receive Port?
  • How can we easily export a binding file from a Send Port?
  • And many more

Today’s blog post will be about: How to Export BizTalk Server Receive Port Binding with PowerShell.

This functionality should be something that should exist in the BizTalk Server Administration Console; in some cases, we can achieve this in the developing phase using the Visual Studio while we generate the schemas for LOB system, for example:

  • In the Solution Explorer, right-click a BizTalk project, point to Add, and then click Add Generated Items.
  • In the Add Generated Items… – <BizTalk ProjectName> dialog box, in the Templates section, click Consume Adapter Service and then click Add
  • You should then select the binding you want to use, configure the parameters and the operations you want to do

Along with the LOB Schemas, this will also generate the binding files for the receive port or send port.

Why we don’t have this option in the BizTalk Server Administration Console for me is unclear, it should be there since day one in my opinion.

So, again, the question that we may ask is: Is there any way that we can easily accomplish this? The response is yes, again, all of this can be fully automated using, for example, PowerShell scripts.

Like the previous samples, we could fully automate this Binding generation for each environment, but once again let’s keep it simple and address what is mandatory and easily forgotten. With this PowerShell sample, we will be able to generate a binding file for a specific assembly name which is deployed in my BizTalk Server environment. The script will perform the following tasks:

  • Generate a Binding file for 3 environments DEV, QA and PRD
  • Changing the NT Group Name for each different environment
  • Generate a specific Receive Port deployed in your environment
function bts-receive-port-exportbindings([string]$bindingFilePath, [string]$appName, [string]$portName, [boolean]$generateDiffEnvBindings)
{
    $portRen = $portName.Replace(" ", "")

    $taskParams = ” ExportBindings /Destination:$bindingfilePath$appName.$portRen.BindingInfo.xml /ApplicationName:$appName ”
    #First version: $p = [diagnostics.process]::start(“BTSTask.exe”, $taskParams)
    Start-Process "BTSTask.exe" $taskParams -Wait

    $xml = (Get-Content "$bindingfilePath$appName.$portRen.BindingInfo.xml")
    foreach($RemoveModuleRef in $xml.BindingInfo.ModuleRefCollection.ModuleRef)
    {
        $xml.BindingInfo.ModuleRefCollection.RemoveChild($RemoveModuleRef)
    }
    foreach($RemoveSendPort in $xml.BindingInfo.SendPortCollection.SendPort)
    {
        $xml.BindingInfo.SendPortCollection.RemoveChild($RemoveSendPort)
    }
    foreach($RemoveReceivePort in $xml.BindingInfo.ReceivePortCollection.ReceivePort)
    {
        if($RemoveReceivePort.Name -ne $portName)
        {
            $xml.BindingInfo.ReceivePortCollection.RemoveChild($RemoveReceivePort)
        }
    }
    $xml.Save("$bindingfilePath$appName.$portRen.BindingInfo.xml")

    if($generateDiffEnvBindings)
    {
        $xml.Save("$bindingfilePath$appName.$portRen.QA.BindingInfo.xml")
        $xml.Save("$bindingfilePath$appName.$portRen.PRD.BindingInfo.xml")
    }
}

THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.

You can download the full script from here: Export BizTalk Server Receive Port Binding with PowerShell

The post BizTalk Bindings Exportation: How to Export BizTalk Server Receive Port Binding with PowerShell appeared first on BizTalk360.