【问题标题】:Create Receive Location and Send Port in Existing BizTalk Application using Powershell使用 Powershell 在现有 BizTalk 应用程序中创建接收位置和发送端口
【发布时间】:2020-06-12 17:19:13
【问题描述】:

我需要使用 Powershell 在已经存在的 BizTalk 应用程序中创建接收位置和发送端口。我只看到了一些关于如何创建应用程序但没有调用的文档。任何建议都是有益的。有些东西被注释掉了,那是因为我不能透露这些信息。我在最后一部分添加了关于如何创建应用程序的知识,但这不是我想要的脚本。下面的程序是我目前所拥有的:

#===Create a receive port and location function===#

Function CreateRPandRL ()
{
    #Creating Receive Port
    $myReceivePort = $catalog.AddNewReceivePort($false)
    $myReceivePort.Name = "My Receive Port"

    #Creating Receive Location
    $myReceiveLocation = $myReceivePort.AddNewReceiveLocation()

    foreach ($handler in $catalog.ReceiveHandlers)
    {
        if ($handler.TransportType.Name -eq "FILE")
        {
            $myReceiveLocation.ReceiveHandler = $handler
            break
        }
    }

    #Associate a transport protocol and file location with receive location
    $myReceiveLocation.TransportType = $catalog.ProtocolTypes["FILE"]
    $myReceiveLocation.Address = #pick-up file location

    #Assign the first receive pipeline found to process the message
    foreach ($pipeline in $catalog.Pipelines)
    {
        if ($pipeline.Type -eq [Microsoft.BizTalk.ExplorerOM.PipelineType] "File_Receive")
        {
            $myReceiveLocation.ReceivePipeline = $pipeline
            break
        }

    #Enable the receive location
    $myReceiveLocation.Enable = $true
    }

    #Try to commit the changes made so far.  If the commit fails, roll back changes
    $catalog.SaveChanges()
}

Function CreateSendPorts($Catalog)
{
    #=== Register a trap handler to discard changes on exceptions ===#

    $ErrorActionPreference="silentlycontinue"
    trap { "Exception encountered:`r`n"; $_; "`r`nDiscarding Changes.`r`n";$Catalog.DiscardChanges();exit; }

    #=== create a new static one-way send port using FILE transport ===#

    $mySendPort = $Catalog.AddNewSendPort($false,$false)
    $mySendPort.Name = "My Send Port"
    $mySendPort.PrimaryTransport.TransportType = $catalog.ProtocolTypes["FILE"]
    $mySendPort.PrimaryTransport.Address = #drop-off file location
    $mySendPort.SendPipeline = $Catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.EdiSend"]

    #=== Persist new ports to BizTalk configuration database ===#

    Write-Host "Adding $mySendPort.Name..."
    $catalog.SaveChanges();
    Write-Host "`r`n $mySendPort.Name has been created."

    #=== specify filters for content-based routing ===#
    Write-Host $mySendPort.Name: Adding a filter
    $mySendPort.Filter = "<Filter><Group>" +
                       "<Statement Property='EDI.ISA06' Operator='0' Value='9999999999'/>" +
                       "<Statement Property='EDI.ST01' Operator='0' Value='999'/>" +
                       "<Statement Property='EDI.IsSystemGeneratedAck' Operator='0' Value='true'/>" +
                       "<Statement Property='BTS.ReceivePortName' Operator='0' Value= $myReceivePort.Name/>" +
                       "</Group></Filter>"
    #=== Persist all changes to BizTalk configuration database ===#

    Write-Host $mySendPort.Name + ": Saving changes"
    $catalog.SaveChanges();
    Write-Host "`r`nFilters for $mySendPort.Name created"

    #===========Changing Send Port status===========#

    #Register a trap handler to discard changes on exceptions
    $ErrorActionPreference="silentlycontinue"
    trap { "Exception encountered:`r`n"; $_; "`r`nDiscarding Changes.`r`n";$Catalog.DiscardChanges();exit; }

    #start the send port to begin processing messages
    $mySendPort.Status = [Microsoft.BizTalk.ExplorerOM.PortStatus] "Started"
    Write-Host "Changing" + $mySendPort.Name + "status to ($mySendPort.Status)..."
    $catalog.SaveChanges()
    Write-Host "Complete."


}
#===Main Script===#

#make sure the ExplorerOM assembly is loaded
[void][System.reflection.Assembly]::LoadwithPartialName("Microsoft.BizTalk.ExplorerOM")

#Connect to the BizTalk management database
$Catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
$Catalog.ConnectionString = "SERVER = #server_address; DATABASE=BizTalkMgmtDB; Integrated Security=SSPI"

#Implementing functions
CreateRPandRL
CreateSendPorts

Start-Sleep -Seconds 60


<#
#===BizTalk Application===#
$app = $Catalog.AddNewApplication()
$app.Name = "TestingPowershellScript"
$app.CreateRPandRL()
$app.CreateSendPorts()
#>

【问题讨论】:

    标签: powershell biztalk


    【解决方案1】:

    哎呀,这让我回到了几年,我很高兴我不是唯一一个为此苦苦挣扎的人。你不想管它,然后切换到BizTalk PowerShell Extensions(关于这方面的信息很粗略),它们在 PowerShell 中使用起来非常容易。

    我从我使用的一些脚本中拼凑起来,并省略了一些花哨的东西,但你想要的基本上是:

    $InitializeDefaultBTSDrive = $false
    Import-Module "$env:BTSINSTALLPATH\SDK\Utilities\PowerShell\BizTalkFactory.PowerShell.Extensions.dll" -WarningAction Ignore
    
    New-PSDrive -Name BizTalk -PSProvider BizTalk -Root BizTalk:\ -Instance $DatabaseName -Database $BizTalkMgmtDb
    

    这打开了一个充满好东西的世界,因为它是作为 PSDrive 加载的,您可以在它周围导航、创建东西、删除东西,以及像任何其他驱动器/文件系统一样使用它,例如:

    Get-ChildItem "BizTalk:\All Artifacts\Receive Locations"
    Get-ChildItem "BizTalk:\All Artifacts\Receive Locations" | Disable-ReceiveLocation
    
    Get-ChildItem "BizTalk:\Platform Settings\Host Instances" | Stop-HostInstance
    Get-ChildItem "BizTalk:\Platform Settings\Host Instances" | Where-Object { $_.IsDisabled -eq $false  } | Start-HostInstance
    
    Get-ChildItem "BizTalk:\All Artifacts\Receive Locations" | Enable-ReceiveLocation
    
    Get-ChildItem -Path "BizTalk:\Health and Activity\Service Instances"
    

    比上面的要多得多,这些都不是你真正想要的,你真正想要的是:

    Import-Bindings -Path "BizTalk:" -Source $bindings
    

    $bindings 是您的 XML 绑定文件。

    【讨论】:

      【解决方案2】:

      我的建议,不要尝试这个。适配器的大部分有用设置都不会被任何 API 公开,因此这可能最多只能让您完成一半。

      相反,编写一个绑定文件的导入脚本,该文件支持所有适配器的所有设置。

      【讨论】:

        猜你喜欢
        • 2011-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多