Recently there was a chance to implement the Power Shell script which will monitor the BizTalk application . It is very simple script which get executed by windows task scheduler at predefined time period. It will start all artifacts of BizTalk which will in stop/disable/unlisted state. If the artifacts are up and running, it will not do anything.
#BizTalk Application Monitoring
$Date = Get-Date
$Logfile = "C:ScriptLogs$(gc env:computername)_$(get-date -f yyyy-MM-dd).log"
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
$test = '----------------------------------------------------------'
LogWrite $test
$test = 'Script Started-BizTalk Monitor at '+$Date.DateTime
LogWrite $test
# Get local BizTalk DBName and DB Server from WMI
$btsSettings = get-wmiobject MSBTS_GroupSetting -namespace 'rootMicrosoftBizTalkServer'
$dbInstance = $btsSettings.MgmtDbServerName
$dbName = $btsSettings.MgmtDbName
# Load BizTalk ExplorerOM
[void] [System.reflection.Assembly]::LoadWithPartialName("Microsoft.BizTalk.ExplorerOM")
$BizTalkOM = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
$BizTalkOM.ConnectionString = "SERVER=$dbInstance;DATABASE=$dbName;Integrated Security=SSPI"
[ARRAY]$apps=$BizTalkOM.Applications
Foreach ($app in $apps)
{
if ($app.Name -like 'BizTalkAppName*')
{
$app.Start(63)
$BizTalkOM.SaveChanges()
$test = $app.Name+ " Started"
LogWrite $test
}
}
$test = 'Script executed sucessfully at '+$Date.DateTime
LogWrite $test
$test = '----------------------------------------------------------'
LogWrite $test
Advertisements