2017-03-21 78 views

回答

3

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

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

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

0

我想第二个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 
    } 
} 
相关问题