Example - PowerShell active monitor scripts

PowerShell active monitor scripts have two instantiated objects available to support successful execution:

Context Variables

The following context variables are available for use in PowerShell active monitor scripts:

Script Timeout

You can configure a script timeout value (in seconds). If the script has not finished executing before the timeout value expires, it aborts.

Minimum: 1

Maximum: 60

Default: 60

Example Script

#

# 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 )

}

}

See Also

Adding and editing a PowerShell active monitor