ActiveXperts Network Monitor ships with a powerful set of pre-defined checks. Each individual check has a static number of configuration items. To monitor other items, or to combine monitoring items, you can make use of custom PowerShell checks.
Most of the built-in checks have a PowerShell equivalent, implemented as a PowerShell (.ps1) script file. Out-of-the-box, each PowerShell script monitors the same items as the built-in check. Feel free to modify the script.
To add a new PowerShell-based Printer monitoring check, do the following:
- On the 'Monitor menu', open 'New Monitoring Check (Script)' and choose 'New PowerShell Check'. The 'PowerShell Check' dialog box appears;
- In the 'Script File' selection box, select 'Printer.ps1';
- In the 'Script Parameters'group box enter the required parameters. You can also load a working sample first by clicking on the 'Click here to load a sample' link.
To customize the above monitoring check, click on the 'Edit button' next to the 'Script File' selection box. Notepad will be launched. You can now make changes to the PowerShell script.
Printer.ps1 script source code
################################################################################# # ActiveXperts Network Monitor PowerShell script, (c) ActiveXperts Software B.V. # For more information about ActiveXperts Network Monitor, visit the ActiveXperts # Network Monitor web site at https://www.activexperts.com ################################################################################# # Script # Printer.ps1 # Description: # This function checks if the printer, indicated by strPrinter, is up and running on # the machine specified by strComputer. # Parameters: # 1) strComputer As String - Hostname or IP address of the computer you want to check # 2) strPrinter As String - Name of the printer # 3) strCredentials As String - 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: # .\Printer.ps1 '<Hostname | IP>' '<Printername>' '<Empty String | Server>' # Sample: # .\Printer.ps1 'localhost' 'HP LaserJet 2300 Series PS' '' ################################################################################# #Parameters param( [string]$strComputer, [string]$strPrinter, [string]$strCredentials ) if ( ([string]$strComputer -eq "") -or ([string]$strPrinter -eq "") ) { $res = "UNCERTAIN: Invalid number of parameters - Usage: .\Printer.ps1 <Computer> <Printer> <Credentials>" echo $res exit } ########################### Get objWMIService ############################# $objWMIService = $null if ( $strCredentials -eq "" ) { $objWMIService = Get-WmiObject -ComputerName $strComputer -Class Win32_Printer } else { $objNmCredentials = new-object -comobject ActiveXperts.NMServerCredentials $strUsername = $objNmCredentials.GetLogin($strCredentials) $strPassword = $objNmCredentials.GetPassword($strCredentials) if ( $strUsername -eq "" ) { $res = "ERROR: No alternate credentials defined for [" + $strCredentials + "]. In the Manager application, select 'Options' from the 'Tools' menu and select the 'Server Credentials' tab to enter alternate credentials" echo $res exit } if ( $strPassword -ne "" ) { $strPasswordSecure = ConvertTo-SecureString -string $strPassword -AsPlainText -Force } $objCredentials = new-object -typename System.Management.Automation.PSCredential $strUsername, $strPasswordSecure $objWMIService = Get-WmiObject -ComputerName $strComputer -Class Win32_Printer -Credential $objCredentials } if ( $objWMIService -eq $null ) { $res = "ERROR: Unable to access '" + $strComputer + "'. Possible reasons: no WMI installed on the remote server, no rights to access remote WMI service, or remote server down" echo $res exit } ########################### END ############################# Foreach ( $x in $objWMIService ) { if ( $x.Name -eq $strPrinter ) { $status = $x.PrinterStatus $result = "" switch ( $status ) { 1 {$result = "Other"} 2 {$result = "Unknown"} 3 {$result = "Running/Full Power"} 4 {$result = "Warning"} 5 {$result = "In Test"} 6 {$result = "Not Applicable"} 7 {$result = "Power Off"} 8 {$result = "Off Line"} 9 {$result = "Off Duty"} 10{$result = "Degraded"} 11{$result = "Not Installed"} 12{$result = "Install Error"} 13{$result = "Power Save - Unknown"} 14{$result = "Power Save - Low Power Mode"} 15{$result = "Power Save - Standby"} 16{$result = "Power Cylce"} 17{$result = "Power Save - Warning"} default {$result = "Unknown"} } } } if ( $result -ne $null ) { $res = "SUCCESS: Printer found (" + $result + ")" echo $res exit } else { $res = "ERROR: Printer [" + $strPrinter + "] not found on print server [" + $strComputer + "]" echo $res exit } #echo $objWMIService