Example - PowerShell performance monitor scripts

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

Context Variables

The following context variables are available for use in PowerShell performance 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 #1

#

# This example looks for a process named 'outlook' and reports its

# current number of threads.

#

# Use the built-in cmdlet named 'Get-Process', also aliased as 'ps'

$processes = ps

$processName = "outlook"

$proc = $processes | where { $_.ProcessName -match $processName }

# Performance monitors must call Context.SetValue() to report results

$Context.SetValue($proc.Threads.Count)

Example Script #2

#

# This example uses a reference variable to look for idle time

# levels and logs the results

#

# Use available context variables

$resultText = "Address: " + $Context.GetProperty("Address");

# Access the reference variable

$monitorValue = $Context.GetReferenceVariable("IdleTime")

# Log if necessary

$resultText = $resultText + ", Idle time: " + $monitorValue.ToString()

$Logger.WriteLine($resultText)

# Always set the performance value

$Context.SetValue($monitorValue);

See Also

Using Performance Monitors

Performance monitors overview

Using the Performance Monitor Library

Working with Performance Monitors

Adding and editing an Active Script Performance Monitor

Adding and Editing an APC UPS Performance Monitor

Adding and editing a PowerShell Scripting performance monitor

Adding and editing a Printer performance monitor

Adding and editing an SNMP Performance Monitor

Adding and editing a SQL Query performance monitor

SQL Query Builder

Adding and editing an SSH Performance Monitor

Adding and Editing a WMI Formatted Performance Monitor

Adding and editing a WMI Performance Monitor