ส่งออกชื่อตัวจัดการพอร์ตส่งแบบไดนามิกของ Biztalk

param
(
 [string] $bizTalkDbServer = ".",    
 [string] $bizTalkDbName = "BizTalkMgmtDb",
 [string] $fileHostInstance = "SendingHost",
 [string] $sendPortName = "sm_dynamic_sp_test"

)

[System.reflection.Assembly]::LoadWithPartialName("Microsoft.BizTalk.ExplorerOM") | Out-Null

$catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
$catalog.ConnectionString = "SERVER=$bizTalkDbServer;DATABASE=$bizTalkDbName;Integrated Security=SSPI"

foreach($sp in $catalog.SendPorts)
{
 if($sp.Name -eq $sendPortName)
 {
  "Found send port $($sp.Name), analyzing send handler"

  foreach($sh in $sp.DynamicSendHandlers)
  {
   if($sh.SendHandler.TransportType.Name -eq "FILE")
   {   
    if($sh.SendHandler.Host.Name -ne $fileHostInstance)
    {
     "Changing $($sh.Name) send handler to '$fileHostInstance' from '$($sh.SendHandler.Host.Name)'"
     $sp.SetSendHandler("FILE", $fileHostInstance)
    }
    else
    {
     "Send handler for $($sp.Name) is already '$fileHostInstance' ignorning .. "
    }   
   }
  }
 }
}

$catalog.SaveChanges()