例 - PowerShell アクティブモニタスクリプト

PowerShell アクティブモニタスクリプトには、実行に成功するために利用できる 2 つのインスタンス化オブジェクトがあります。

コンテキスト変数

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 )

}

}

参照

PowerShell アクティブモニタの追加および編集