PowerShell 主動監控工具指令碼提供兩個實體化的物件,使得執行作業能夠成功:
您可在 PowerShell 主動監控工具指令碼中使用以下環境變數:
您可以設定指令碼的逾時值 (以秒為單位)。 若指令碼在逾時值到期之前還是沒有執行完成,作業就會直接中止。
最小值: 1
最大值: 60
預設值: 60
#
# This example looks for a process named 'outlook' and reports if its
# responding
#
# Use the built-in cmdlet named 'Get-Process', also aliased as 'ps'
$processes = ps
$processName = "outlook"
$proc = $processes | where { $_.ProcessName -match $processName }
# Active monitors must call Context.SetResult() to report results
if ($proc -eq $Null)
{
$NotRunningMessage = "Process '" + $processName + "' is not running."
$Context.SetResult(1, $NotRunningMessage )
}
else
{
if ($proc.Responding)
{
$RespondingMessage = "Process '" + $processName + "' is responding."
$Context.SetResult(0, $RespondingMessage )
}
else
{
$NotRespondingMessage = "Process '" + $processName + "' is not responding."
$Context.SetResult(1, $NotRunningMessage )
}
}