【问题标题】:PowerShell scripts to automate BizTalk configurations用于自动化 BizTalk 配置的 PowerShell 脚本
【发布时间】:2017-08-13 07:22:23
【问题描述】:

我需要帮助来自动化 BizTalk 配置,例如发送/接收位置等。 我认为我们可以使用 PowerShell 脚本来实现这一点。

有什么建议吗?

注意:我们有本地基础设施。

【问题讨论】:

    标签: .net powershell automation biztalk biztalk-2010


    【解决方案1】:

    为了便于 BizTalk Server、端口、绑定等的管理时配置,您将专注于使用绑定文件。

    虽然 Powershell 可以成为其中的一部分,但 Powershell 本身并不是驱动配置的因素​​。

    也许您真正应该关注的是使用 Deployment Framework for BizTalk (BTDF) 自动部署应用程序。

    【讨论】:

      【解决方案2】:

      我赞成 Johns-305 的回答 - 如果您尝试配置应用程序绑定,您应该利用绑定文件,并且一定要考虑使用 BTDF 来管理多个环境。

      另一方面,如果您尝试自动设置主机/主机实例/适配器处理程序,PowerShell 可以是一个很好的工具,可以简化跨环境的一致部署。您可以使用 BizTalk PowerShell 提供程序(如何使用 here 或使用 WMI 的多个示例(here 的绝佳示例。

      在第二个链接中,这是一个使用 WMI 删除或创建适配器处理程序的示例(它不需要像 BizTalk PowerShell 提供程序这样的任何特殊加载项 - 虽然它是一个很棒的加载项,但并不总是适用于给定环境):

      #############################################################
      # This function will delete an existente host handlers 
      # in the adapters.
      # [direction]: 'Receive','Send'
      #############################################################
      function DeleteBizTalkAdapterHandler (
          [string]$adapterName,
          [string]$direction,
          [string]$hostName)
      {
          try
          {
              if($direction -eq 'Receive')
              {
                  [System.Management.ManagementObject]$objHandler = get-wmiobject 'MSBTS_ReceiveHandler' -namespace 'root\MicrosoftBizTalkServer' -filter "HostName='$hostName' AND AdapterName='$adapterName'"
                  $objHandler.Delete()
              }
              else
              {
                  [System.Management.ManagementObject]$objHandler = get-wmiobject 'MSBTS_SendHandler2' -namespace 'root\MicrosoftBizTalkServer' -filter "HostName='$hostName' AND AdapterName='$adapterName'"
                  $objHandler.Delete()
              }
      
              Write-Host "$direction handler for $adapterName / $hostName was successfully deleted" -Fore DarkGreen
          }
          catch [System.Management.Automation.RuntimeException]
          {
              if ($_.Exception.Message -eq "You cannot call a method on a null-valued expression.")
              {
                  Write-Host "$adapterName $direction Handler for $hostName does not exist" -Fore DarkRed
              }
              elseif ($_.Exception.Message.IndexOf("Cannot delete a receive handler that is used by") -ne -1)
              {
                  Write-Host "$adapterName $direction Handler for $hostName is in use and can't be deleted." -Fore DarkRed
              }
              elseif ($_.Exception.Message.IndexOf("Cannot delete a send handler that is used by") -ne -1)
              {
                  Write-Host "$adapterName $direction Handler for $hostName is in use and can't be deleted." -Fore DarkRed
              }
              elseif ($_.Exception.Message.IndexOf("Cannot delete this object since at least one receive location is associated with it") -ne -1)
              {
                  Write-Host "$adapterName $direction Handler for $hostName is in use by at least one receive location and can't be deleted." -Fore DarkRed
              }
              else
              {
                  write-Error "$adapterName $direction Handler for $hostName could not be deleted: $_.Exception.ToString()"
              }
          }
      }
      
      #############################################################
      # This function will create a handler for a specific 
      # adapter on the new host, so these get used for processing.
      # [direction]: 'Receive','Send'
      #############################################################
      function CreateBizTalkAdapterHandler(
          [string]$adapterName,
          [string]$direction,
          [string]$hostName,
          [string]$originalDefaulHostName,
          [boolean]$isDefaultHandler,
          [boolean]$removeOriginalHostInstance)
      {
          if($direction -eq 'Receive')
          {
              [System.Management.ManagementObject]$objAdapterHandler = ([WmiClass]"root/MicrosoftBizTalkServer:MSBTS_ReceiveHandler").CreateInstance()
              $objAdapterHandler["AdapterName"] = $adapterName
              $objAdapterHandler["HostName"] = $hostName
          }
          else
          {
              [System.Management.ManagementObject]$objAdapterHandler = ([WmiClass]"root/MicrosoftBizTalkServer:MSBTS_SendHandler2").CreateInstance()
              $objAdapterHandler["AdapterName"] = $adapterName
              $objAdapterHandler["HostName"] = $hostName
              $objAdapterHandler["IsDefault"] = $isDefaultHandler
          }
      
          try
          {
              $putOptions = new-Object System.Management.PutOptions
              $putOptions.Type = [System.Management.PutType]::CreateOnly;
      
              [Type[]] $targetTypes = New-Object System.Type[] 1
              $targetTypes[0] = $putOptions.GetType()
      
              $sysMgmtAssemblyName = "System.Management"
              $sysMgmtAssembly = [System.Reflection.Assembly]::LoadWithPartialName($sysMgmtAssemblyName)
              $objAdapterHandlerType = $sysMgmtAssembly.GetType("System.Management.ManagementObject")
      
              [Reflection.MethodInfo] $methodInfo = $objAdapterHandlerType.GetMethod("Put", $targetTypes)
              $methodInfo.Invoke($objAdapterHandler, $putOptions)
      
              Write-Host "$adapterName $direction Handler for $hostName was successfully created" -Fore DarkGreen
          }
          catch [System.Management.Automation.RuntimeException]
          {
              if ($_.Exception.Message.Contains("The specified BizTalk Host is already a receive handler for this adapter.") -eq $true)
              {
                  Write-Host "$hostName is already a $direction Handler for $adapterName adapter." -Fore DarkRed
              }
              elseif($_.Exception.Message.Contains("The specified BizTalk Host is already a send handler for this adapter.") -eq $true)
              {
                  Write-Host "$hostName is already a $direction Handler for $adapterName adapter." -Fore DarkRed
              }
              else {
                  write-Error "$adapterName $direction Handler for $hostName could not be created: $_.Exception.ToString()"
              }
          }
      
          if($removeOriginalHostInstance)
          {
              DeleteBizTalkAdapterHandler $adapterName $direction $originalDefaulHostName
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2021-10-29
        • 1970-01-01
        • 2011-07-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-30
        • 2017-08-08
        • 2010-09-06
        相关资源
        最近更新 更多