Share via


BizTalk: Get status of all artifacts using PowerShell

Have you ever wondered how to write a PowerShell script to get the status of all BizTalk artifacts like Receive locations, Send Ports, Orchestrations, Host Instances and Applications?

 

Following is the list of functions which gives you list of all BizTalk artifacts.

#-------------Declaration------------------------

 

Set-ExecutionPolicy Unrestricted
  
# Import assembly
[void] [System.reflection.Assembly]::LoadWithPartialName("Microsoft.BizTalk.ExplorerOM")
#create a new object
$Catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
  
#BizTalk Config
$Catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"  #Connection string to BizTalk Mgmt database

 

 

 

 

#----------------Receive Locations---------------------

 

/*  $receiveLoc.Enable returns value true or false. So we can use this filed to determine whether receive locations is Enabled or Disabled.

 

*/

 

function getReceiveLocationStatus()
{
    write-host ""
    write-host ""
  
  "{0,-50} {1,-20} " -f ` "Receive Location","Status"
  "{0,-50} {1,-20} " -f ` "--------------------","----------"
  
   foreach ($receivePort in $catalog.ReceivePorts)
   {
       foreach($receiveLoc in $receivePort.ReceiveLocations)
        {
           "{0,-50} {1,-20} " -f ` $receiveLoc.Name, $receiveLoc.Enable    
        }
         
   }
}

 

 

 

#----------------Orchestrations---------------------

 

Function GetOrchestrationStatus()
{
  
Write-Host ""
Write-Host ""
  
  "{0,-80} {1,-20} " -f ` "Orchestration","Status"
  
  "{0,-80} {1,-20} " -f ` "--------------------","----------"
  
    foreach($assembly in $catalog.Assemblies)
    {
        foreach($orch in $assembly.Orchestrations)
        {
           "{0,-80} {1,-20} " -f ` $orch.Fullname,$orch.Status
        }
    }
}

  

#----------------Applications---------------------

 

 

function getApplicationStatus()
{
    write-host ""
    write-host ""
  
  "{0,-50} {1,-20} " -f ` "Application","Status"
  "{0,-50} {1,-20} " -f ` "--------------------","----------"
   foreach ($app in $catalog.Applications)
   {
       "{0,-50} {1,-20} " -f ` $app.Name,$app.Status
   }
  "{0,-50} {1,-20} " -f ` "--------------------","----------"
}

 

 

 

#----------------Send Ports---------------------

 

 

function getSendPortStatus()
{
    write-host ""
    write-host ""
  
  "{0,-50} {1,-20} " -f ` "Send Port","Status"
  "{0,-50} {1,-20} " -f ` "--------------------","----------"
   foreach ($sendport in $catalog.SendPorts)
   {
     "{0,-50} {1,-20} " -f ` $sendPort.Name,$sendPort.Status
   }
  "{0,-50} {1,-20} " -f ` "--------------------","----------"
}

 

 

 

#----------------Host Instances---------------------

 

/*   Service State in the host instance is numeric and the values are as follows:

 

Stopped:                       1

Start pending:                2

Stop pending:                3

Running:                      4

Continue pending:          5

Pause pending:             6

Paused:                        7

Unknown:                     8

 

*/

 

 

 

 

function getHostsStatus()
{
    write-host ""
    write-host ""
  
  "{0,-50} {1,-20} " -f ` "Host Instance","Status"
  "{0,-50} {1,-20} " -f ` "--------------------","----------"
  
   $hosts = Get-WmiObject MSBTS_HostInstance -namespace 'root/MicrosoftBizTalkServer'
   foreach ($hostinst in $hosts)
   {
      "{0,-50} {1,-20} " -f ` $hostinst.HostName,$hostinst.ServiceState
   }
  "{0,-50} {1,-20} " -f ` "--------------------","----------"
}

 

      

getReceiveLocationStatus

getSendPortStatus

GetOrchestrationStatus

getHostsStatus

getApplicationStatus