Ravindar, Biztalk Developer and Administrator

Just another BizTalk blog

access Ports from Powershell

A user asked in the forums here how to access ports through wmi.

my sample solution to access ports is below


Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer catalog = new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer();

foreach (Microsoft.BizTalk.ExplorerOM.Application application in catalog.Applications)
            {


                foreach (Microsoft.BizTalk.ExplorerOM.ReceivePort recport in application.ReceivePorts)
                {
                    foreach (Microsoft.BizTalk.ExplorerOM.ReceiveLocation recloc in recport.ReceiveLocations)
                    {
                        System.Console.Write(recloc.Address);
                    }

                }



                foreach (Microsoft.BizTalk.ExplorerOM.SendPort sendport in application.SendPorts)
                {
                    System.Console.Write(sendport.PrimaryTransport.Address);
                }


            }


Also another user asked here wanted to unbound an orchestration completely programmatically. here is the solution

[void] [System.reflection.Assembly]::LoadWithPartialName("Microsoft.BizTalk.ExplorerOM")

#=== Connect to the BizTalk Management database ===#

$Catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
$Catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"


$MyApplication = $Catalog.Applications["TestApp"]
$MyApplication.Stop(63)
 $Catalog.SaveChanges()
$orch = $MyApplication.orchestrations

foreach ($CurrentOrchestration in $orch)
{
    $CurrentOrchestration.Host=$null
    $CurrentOrchestration.Status = [Microsoft.BizTalk.ExplorerOM.OrchestrationStatus] "Enlisted"
    
    $CurrentOrchestration.Status = [Microsoft.BizTalk.ExplorerOM.OrchestrationStatus] "Unenlisted"
    
    
    foreach ($CurrentPort in $CurrentOrchestration.Ports)
        {            
                $CurrentPort.ReceivePort=$null
                $CurrentPort.SendPort=$null
         
        }

}
 $Catalog.SaveChanges()

January 9, 2015 Posted by | Uncategorized | Leave a comment