This post was originally published here

Finally, the last blog post on this series about BizTalk Bindings Exportation 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
  • How can we easily export a binding file from a Receive Port?
  • How can we easily export a binding file from a Send Port?
  • How can we easily export a binding file from a list of assemblies?
    • By fully qualified name (FQName);
    • By assembly names;

Today’s blog post will be about: How to Export BizTalk Server Bindings by a List of Port Names with PowerShell.

In other words, instead of generating a specific binding file for each port: Receive Port and/or Send Port, we will include all of the receive ports and send ports bindings in a unique binding file, so it can easily be handled.

This functionality should be something that should exist in the BizTalk Server Administration Console, but it is impossible to be addressed using the out-of-the-box tool BizTalk Server Administration Console or even with the BTSTask command-line tool which is included with BizTalk Server.

As always, and like the previous samples, we could fully automate this Binding generation for each environment, but once again let’s keep it simple. 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
  • Generate a unique binding file, instead of having separated binding files for each Port name (receive port and/or send port)
function bts-list-ports-exportbindings([string]$bindingFilePath, [string]$bindingNamePrefix, [string]$appName, [string]$rcvPortNames, [string]$sndPortNames, [boolean]$generateDiffEnvBindings)
{
    $finalBinding = (Get-Content "C:TempBTSTemplateBindingInfo.xml")
    $moduleRefNode = $finalBinding.SelectSingleNode("BindingInfo/ModuleRefCollection")
    $sendPortNode = $finalBinding.SelectSingleNode("BindingInfo/SendPortCollection")
    $receivePortNode = $finalBinding.SelectSingleNode("BindingInfo/ReceivePortCollection")

    $listRcvPorts = $rcvPortNames.Split("|")
    $listSndPorts = $sndPortNames.Split("|")

    $taskParams = ” ExportBindings /Destination:$bindingfilePath$appName.BindingInfo.xml /ApplicationName:$appName ”
    Start-Process "BTSTask.exe" $taskParams -Wait

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

    foreach($receivePortBinding in $xml.BindingInfo.ReceivePortCollection.ReceivePort)
    {
        if($listRcvPorts -Contains $receivePortBinding.Name)
        {
            $node = $finalBinding.ImportNode(($receivePortBinding), $true);
            $receivePortNode.AppendChild($node);
        }
    }

    foreach($sendPortBinding in $xml.BindingInfo.SendPortCollection.SendPort)
    {
        if($listSndPorts -Contains $sendPortBinding.Name)
        {
            $node = $finalBinding.ImportNode(($sendPortBinding), $true);
            $sendPortNode.AppendChild($node);
        }
    }

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

    if($generateDiffEnvBindings)
    {
        $finalBinding.Save("$bindingfilePath$bindingNamePrefix.QA.BindingInfo.xml")
        $finalBinding.Save("$bindingfilePath$bindingNamePrefix.PRD.BindingInfo.xml")
    }
}

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

We will not change the URI for each environment – it could be done, but is not the goal here, it is just a start.

You can download the full script from here: Export BizTalk Server Bindings from a List of Port Names with PowerShell

The post BizTalk Bindings Exportation: How to Export BizTalk Server Bindings by a List of Port Names with PowerShell appeared first on BizTalk360.