BizTalk Bindings Exportation: How to Export BizTalk Server Resource Bindings from a List of Assemblies FQName with PowerShell

Until now, we have been addressing single operations, like generating binding files for one Receive or Send Port port or a single Assembly. Some of these default operations can be achieved with out-of-the-box tools (BizTalk Server Administration Console or even with BTSTask command-line tool included with BizTalk Server), other more advanced scenarios extend the default functionalities:

From now on, we will be addressing some of the previous features described in this series of posts, but this time aggregating several operations for example:

  • How can we easily export a binding file from a list of assemblies?
    • By fully qualified name (FQName)
    • By assembly names
  • How can we easily export a binding file from a list of Receive Ports?
  • How can we easily export a binding file from a list of Send Ports?

In other words, instead of generating a specific binding file for each resource: Receive Port, Send Port or Assembly, we will be generating a unique binding file that will include all this information, so it can easily be handled.

Today’s blog post will be about: How to Export BizTalk Server Resource Bindings from a List of Assemblies FQName with PowerShell.

Out-of-the-box, we can export a binding file for a specific assembly which is deployed in your BizTalk Server environment. But if you have 10 assemblies then you will be forced to generate them one by one and you will end up with:

  • 10 different binding files that you can provide to your administration team
  • Or manually merge them into one and provide them to your administration team

This manual intervention, besides being monotonous, boring and time-consuming is subject to many failures. So the normal question is, is there any way that we can improve this experience? And the response is yes, 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 unique binding file for a list of specific assemblies deployed in my BizTalk Server environment. The script will take care of 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 unique binding file, instead of having separated binding files for each assembly
function bts-list-resource-exportbindings-by-assembly-fqname([string]$bindingFilePath, [string]$appName, [string]$listAssemblyFQName, [boolean]$generateDiffEnvBindings)
{
    $finalBinding = (Get-Content "C:\Temp\BTS\TemplateBindingInfo.xml")
    $moduleRefNode = $finalBinding.SelectSingleNode("BindingInfo/ModuleRefCollection")
    $sendPortNode = $finalBinding.SelectSingleNode("BindingInfo/SendPortCollection")
    $receivePortNode = $finalBinding.SelectSingleNode("BindingInfo/ReceivePortCollection")

    $list = $listAssemblyFQName.Split("|")

    foreach($element in $list)
    {
        $dllName = $element.Substring(0, $element.IndexOf(','))
        $taskParams = ” ExportBindings /Destination:$bindingfilePath$appName.$dllName.BindingInfo.xml /AssemblyName:""$element"" ”
        Start-Process "BTSTask.exe" $taskParams -Wait

        $xml = (Get-Content "$bindingfilePath$appName.$dllName.BindingInfo.xml")

        foreach($moduleRef in $xml.BindingInfo.ModuleRefCollection.ModuleRef)
        {
            $node = $finalBinding.ImportNode(($moduleRef), $true);
            $moduleRefNode.AppendChild($node);
        }
        foreach($sendPort in $xml.BindingInfo.SendPortCollection.SendPort)
        {
            $node = $finalBinding.ImportNode(($sendPort), $true);
            $sendPortNode.AppendChild($node);
        }
        foreach($receivePort in $xml.BindingInfo.ReceivePortCollection.ReceivePort)
        {
            $node = $finalBinding.ImportNode(($receivePort), $true);
            $receivePortNode.AppendChild($node);
        }
    }

    $finalBinding.Save("$bindingfilePath$appName.BindingInfo.xml")

    if($generateDiffEnvBindings)
    {
        $xml = (Get-Content "$bindingfilePath$appName.BindingInfo.xml")
    
        # QA Binding Info Generation
        $xml.SelectNodes("//Host") | % { 
            $_.NtGroupName = $global:qaNTGroupName
        }
        $xml.Save("$bindingfilePath$appName.QA.BindingInfo.xml")

        # PRD Binding Info Generation
        $xml.SelectNodes("//Host") | % { 
            $_.NtGroupName = $global:prdNTGroupName
        }
        $xml.Save("$bindingfilePath$appName.PRD.BindingInfo.xml")
    }
}

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

You can download the full script from here: Export BizTalk Resource Bindings from List of Assemblies FQName with PowerShell

Author: Sandro Pereira

Sandro Pereira is an Azure MVP and works as an Integration 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.

Back to Top