BizTalk Bindings Exportation: How to Export BizTalk Server Resource Bindings from a List of Assembly Names with PowerShell

On the last blog post and PowerShell sample we addressed, for the first time in the series of posts, a way to aggregate several binding exportations in a unique binding file based on a list of assemblies with fully qualified names (FQName):

Today’s blog post will be similar, but instead of using the FQName, we will be using the assembly name only: How to Export BizTalk Server Resource Bindings from a List of Assembly Names with PowerShell

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 of this information so it can easily be handled.

Recapping also the samples we have shared until now:

And to unveil the last chapter of this series that we will be publishing soon:

  • How can we easily export a binding file from a list of Receive Ports and/or Send Ports?

Just 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 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 unique binding file, instead of having separated binding files for each assembly
function bts-list-resource-exportbindings-by-assembly-name([string]$bindingFilePath, [string]$appName, [string]$listAssemblyName, [boolean]$generateDiffEnvBindings)
{
    #splits all the assemblies by |
    $list = $listAssemblyName.Split("|") 
    $finalBinding = (Get-Content "C:\Temp\TemplateBindingInfo.xml")
    $moduleRefNode = $finalBinding.SelectSingleNode("BindingInfo/ModuleRefCollection")
    $sendPortNode = $finalBinding.SelectSingleNode("BindingInfo/SendPortCollection")
    $receivePortNode = $finalBinding.SelectSingleNode("BindingInfo/ReceivePortCollection")
    $displayName = 'assemblyName'
    $appsList=New-Object System.Collections.ArrayList
    $assemblyListFQN = New-Object System.Collections.ArrayList     
    $appsList = BTSTask.exe ListApp /ApplicationName:$appName
    #region Add FQN to list
    foreach($string in $appsList)
    {         
        #region Get Assembly Fully Qualified Name
        $list = $listAssemblyName.Split("|")
                    
        foreach($element in $list)
        { 
            if($string.Contains('-'))
            {
                if($string.Split('-')[1].Split('"')[1] -eq "System.BizTalk:BizTalkAssembly")
                {
                    foreach($element in $list){      
                        if($string.Split('-')[2].Split('"')[1].StartsWith($element))
                        {
                            if(!$assemblyListFQN.Contains($string.Split('-')[2].Split('"')[1])){
                                $assemblyListFQN.Add($string.Split('-')[2].Split('"')[1]);
                                #display name Set
                            }
                        }
                    }
                }
            }
        }
        #endregion   
    }
    #endregion
    
    #loop assemblies
    foreach($string in $assemblyListFQN)
    {        
        $dllName = $string.Substring(0, $string.IndexOf(','))
        $taskParams = ” ExportBindings /Destination:$bindingfilePath$appName.$dllName.BindingInfo.xml /AssemblyName:""$string"" ”
        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")

    #generate different Environments Bindings
    if($generateDiffEnvBindings)
    {
        $xml = (Get-Content "$bindingfilePath$appName.BindingInfo.xml")
    
        # QA Binding Info Generation
        $xml.SelectNodes("//Host") | % { 
            if(!$_.Attributes['xsi:nil'].Value)
            {
                $_.NtGroupName = $global:qaNTGroupName
            }
        }
        $xml.Save("$bindingfilePath$appName.QA.BindingInfo.xml")

        # PRD Binding Info Generation
        $xml.SelectNodes("//Host") | % { 
            if(!$_.Attributes['xsi:nil'].Value)
            {
                $_.NtGroupName = $global:prdNTGroupName
            }
        }
        $xml.Save("$bindingfilePath$appName.PRD.BindingInfo.xml")
    }
}

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

To be honest, I think this is the less useful script because it is not that much practical use, and also it will have several limitations when we have several and different versions of the same published DLL. But, it can be very useful and practical in situations where we can guarantee that we have only one DLL version published in our environment.

You can download the full script from here: Export BizTalk Resource Bindings from a List of Assembly Names 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