Let’s go for the eighth and last PowerShell sample in a series of posts that, once again, I will be addressing some of the real case scenarios that we may face daily:

Today sample will be about: How to Export BizTalk Server Resource Bindings from a List of Port Names with PowerShell

With this PowerShell sample we will be able to generate a unique binding file for a list of specific assemblies name deployed in my BizTalk Server environment:

PowerShell
Edit|Remove
function bts-list-ports-exportbindings([string]$bindingFilePath, [string]$bindingNamePrefix, [string]$appName, [string]$rcvPortNames, [string]$sndPortNames, [boolean]$generateDiffEnvBindings) 
{ 
    $finalBinding = [xml](Get-Content"C:\Temp\BTS\TemplateBindingInfo.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 = [xml](Get-Content"$bindingfilePath$appName.BindingInfo.xml") 
 
    foreach($receivePortBindingin$xml.BindingInfo.ReceivePortCollection.ReceivePort) 
    { 
        if($listRcvPorts-Contains $receivePortBinding.Name) 
        { 
            $node = $finalBinding.ImportNode(($receivePortBinding), $true); 
            $receivePortNode.AppendChild($node); 
        } 
    } 
 
    foreach($sendPortBindingin$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.

About Me

Sandro Pereira
DevScope | MVP & MCTS BizTalk Server 2010
https://blog.sandro-pereira.com/ | @sandro_asp