Let’s go for the fourth 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 Receive Port Binding with PowerShell

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

PowerShell
Edit|Remove
function bts-receive-port-exportbindings([string]$bindingFilePath, [string]$appName, [string]$portName, [boolean]$generateDiffEnvBindings) 
{ 
    $portRen = $portName.Replace(" """) 
 
    $taskParams = ” ExportBindings /Destination:$bindingfilePath$appName.$portRen.BindingInfo.xml /ApplicationName:$appName ” 
    #First version: $p = [diagnostics.process]::start(“BTSTask.exe”, $taskParams) 
    Start-Process"BTSTask.exe"$taskParams-Wait 
 
    $xml = [xml](Get-Content"$bindingfilePath$appName.$portRen.BindingInfo.xml") 
    foreach($RemoveModuleRefin$xml.BindingInfo.ModuleRefCollection.ModuleRef) 
    { 
        $xml.BindingInfo.ModuleRefCollection.RemoveChild($RemoveModuleRef) 
    } 
    foreach($RemoveSendPortin$xml.BindingInfo.SendPortCollection.SendPort) 
    { 
        $xml.BindingInfo.SendPortCollection.RemoveChild($RemoveSendPort) 
    } 
    foreach($RemoveReceivePortin$xml.BindingInfo.ReceivePortCollection.ReceivePort) 
    { 
        if($RemoveReceivePort.Name -ne $portName) 
        { 
            $xml.BindingInfo.ReceivePortCollection.RemoveChild($RemoveReceivePort) 
        } 
    } 
    $xml.Save("$bindingfilePath$appName.$portRen.BindingInfo.xml") 
 
    if($generateDiffEnvBindings) 
    { 
        $xml.Save("$bindingfilePath$appName.$portRen.QA.BindingInfo.xml") 
        $xml.Save("$bindingfilePath$appName.$portRen.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