Let’s go for the fifth 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 Assemblies FQName 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-resource-exportbindings-by-assembly-fqname([string]$bindingFilePath, [string]$appName, [string]$listAssemblyFQName, [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") 
 
    $list = $listAssemblyFQName.Split("|") 
 
    foreach($elementin$list) 
    { 
        $dllName = $element.Substring(0, $element.IndexOf(',')) 
        $taskParams = ” ExportBindings /Destination:$bindingfilePath$appName.$dllName.BindingInfo.xml /AssemblyName:""$element"" ” 
        Start-Process"BTSTask.exe"$taskParams-Wait 
 
        $xml = [xml](Get-Content"$bindingfilePath$appName.$dllName.BindingInfo.xml") 
 
        foreach($moduleRefin$xml.BindingInfo.ModuleRefCollection.ModuleRef) 
        { 
            $node = $finalBinding.ImportNode(($moduleRef), $true); 
            $moduleRefNode.AppendChild($node); 
        } 
        foreach($sendPortin$xml.BindingInfo.SendPortCollection.SendPort) 
        { 
            $node = $finalBinding.ImportNode(($sendPort), $true); 
            $sendPortNode.AppendChild($node); 
        } 
        foreach($receivePortin$xml.BindingInfo.ReceivePortCollection.ReceivePort) 
        { 
            $node = $finalBinding.ImportNode(($receivePort), $true); 
            $receivePortNode.AppendChild($node); 
        } 
    } 
 
    $finalBinding.Save("$bindingfilePath$appName.BindingInfo.xml") 
 
    if($generateDiffEnvBindings) 
    { 
        $xml = [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.

About Me

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