范例:PowerShell 主动监控工具脚本

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 )

}

}

另请参阅

添加和编辑 PowerShell 主动监控工具