process.ps1 - powershell script by ActiveXperts Software
process.ps1 checks whether a process is running. Checks CPU and memory resources as well.
Use process.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select process.ps1. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
process.ps1 script code
################################################################################# # ActiveXperts Network Monitor PowerShell script, © ActiveXperts Software B.V. # For more information about ActiveXperts Network Monitor, visit the ActiveXperts # Network Monitor web site at http://www.activexperts.com ################################################################################# # Script: # Process.ps1 # Description: # Checks if a process, specified by strProcess, is running on the machine specified by strHost. # Declare Parameters: # 1) strHost (string) - Hostname or IP # 1) strProcess (string) - Name of the process to check # 3) strAltCredentials (string, optional) - Specify an empty string to use Network Monitor service credentials. # To use alternate credentials, enter a server that is defined in Server Credentials table. # (To define Server Credentials, choose Tools->Options->Server Credentials) # Usage: # .\Process.ps1 '<Hostname | IP>' '<Process Name>' '[alt-credentials]' # Sample: # .\Process.ps1 'localhost' 'winlogon' ################################################################################# # -- Declare Parameters param( [string]$strHost = '', [string]$strProcess = '', [string]$strAltCredentials = '' ) # -- Use _activexperts.ps1 with common functions . 'C:\Program Files\ActiveXperts\Network Monitor\Scripts\Monitor (ps1)\_activexperts.ps1' ################################################################################# # // --- Main script --- ################################################################################# # -- Clear screen and clear error cls $Error.Clear() # -- Validate parameters, return on parameter mismatch if( $strHost -eq '' -or $strProcess -eq '' ) { echo 'UNCERTAIN: Invalid number of parameters - Usage: .\Process.ps1 "<Hostname | IP>" "<Process Name>" "[alt-credentials]"' exit } # Declare local variables by assigning an initial value to it $lstProcesses = $null $objAltCredentials = $null $strExplanation = '' # If alternate credentials are specified, retrieve the alternate login and password from the ActiveXperts global settings if( $strAltCredentials -ne '' ) { # Get the Alternate Credentials object. Function "AxGetCredentials" is implemented in "activexperts.ps1" if( ( AxGetCredentials $strHost $strAltCredentials ([ref]$objAltCredentials) ([ref]$strExplanation) ) -ne $AXSUCCESS ) { echo $strExplanation exit } } $lstProcesses = @( $strProcess, '' ) # -- Check processes if( ( AxCheckProcesses $strHost ([ref]$lstProcesses) $objAltCredentials ([ref]$strExplanation) ) -ne $AXSUCCESS ) { echo $strExplanation exit } # -- Print script result $res = 'SUCCESS: Process [' + $strProcess + '] is running on [' + $strHost + ']' echo $res exit ################################################################################# # // --- Catch script exceptions --- ################################################################################# trap [Exception] { $res = 'UNCERTAIN: ' + $_.Exception.Message echo $res exit }