PowerShell を初めて使用するので、助けが必要です。以下は、BizTalk でホスト インスタンスの状態を確認するための標準的なスクリプトです。
2 つのタスクがあります。1. スクリプトの出力をメールで送信します。2. PS スクリプトをスケジュールします。
$servers = (".")
#This function checks the status of the host instances on a BizTalk server ($Server).
function checkhostinstancestatusstarted ($server)
{
#gets all host instances on the server. Isolated (hosttype = 2) or disabled hosts are excluded .
$hostinstances = get-wmiobject MSBTS_HostInstance -namespace 'root\MicrosoftBizTalkServer' | where {$_.runningserver -match $server -AND $_.hosttype -ne "2" -and $_.IsDisabled -ne "True"}
write-host "Checking the state of all host instances on the server $server`:"
foreach ($hostinstance in $hostinstances)
{
$HostInstanceName = $HostInstance.hostname
#Checks the host instance state
if ($HostInstance.ServiceState -eq 1)
{
write-host "$HostInstanceName`: Stopped."
}
elseif ($HostInstance.ServiceState -eq 2)
{
write-host "$HostInstanceName`: Start pending."
}
elseif ($HostInstance.ServiceState -eq 3)
{
write-host "$HostInstanceName`: Stop pending."
}
elseif ($HostInstance.ServiceState -eq 4)
{
write-host "$HostInstanceName`: Started."
}
elseif ($HostInstance.ServiceState -eq 5)
{
write-host "$HostInstanceName`: Continue pending."
}
elseif ($HostInstance.ServiceState -eq 6)
{
write-host "$HostInstanceName`: Pause pending."
}
elseif ($HostInstance.ServiceState -eq 7)
{
write-host "$HostInstanceName`: Paused."
}
elseif ($HostInstance.ServiceState -eq 8)
{
write-host "$HostInstanceName`: Unknown."
}
}
write-host `n
}
foreach ($server in $servers)
{
checkhostinstancestatusstarted $server
}