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

Creating custom performance monitors

Creating device-specific Active Script performance monitors

Creating device-specific APC UPS performance monitors

Creating device-specific PowerShell Scripting performance monitors

Creating device-specific SNMP performance monitors

Creating device-specific Printer performance monitors

Creating device-specific SQL Query performance monitors

SQL Query Builder

Creating device-specific SSH performance monitors

Creating device-specific WMI Formatted Counter performance monitors

Creating device-specific WMI performance monitors

Example: monitoring router bandwidth

Example: troubleshooting a slow network connection