Contact Info

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 Service-CheckMultipleServices monitoring check, do the following:

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.

Powershell Service-CheckMultipleServices check

Service-CheckMultipleServices.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
#     Service-CheckService.ps1
# Description:
#     Checks if a service, specified by strService, is running on the machine specified by strComputer.
# Parameters:
#     1) strComputer As String - Hostname or IP address of the computer you want to check
#     3) strServices As String - List of services; the services are separated by the ';' character
#     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:
#      .\Service-CheckService.ps1 '<strComputer>' '<strService_1;strService_2;..;service_n>' '[strCredentials]' 
# Sample:
#      .\Service-CheckService.ps1 'localhost' 'ActiveXperts Network Monitor;power'
#################################################################################

#parameters
param
(
  [string]$strComputer,  
  [string]$strService,
  [string]$strCredentials
)

if ( ([string]$strComputer -eq "") -or
     ([string]$strService -eq "")  
   )
{
  $res = "UNCERTAIN: Invalid number of parameters - Usage: .\Service-CheckService.ps1 '<strComputer>' '<strService>' '[strCredentials]'"
  echo $res
  exit
}

$objWMIService = $null
    
if ( $strCredentials -eq "" )
{
  $objWMIService = Get-WmiObject -ComputerName $strComputer -Class Win32_Service
}
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_Service -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
}

$colServices = $strService.Split(";")

$bFound = 0
$strFailed = ""
$strSuccess = ""
$strNotFound = ""

Foreach ( $str in $colServices )
{
  $bfound = 0
  ForEach ( $objService in $objWMIService )
  {
    if ( ($objService.Name -eq $str) -or ($objService.DisplayName -eq $str) )
    {
      $bfound = 1
      if ( $objService.State -ne "Running" )
      {
        $strFailed = $strFailed + "(" + $str + ":" + $objService.State + ")"
      }
      else
      {
        $strSuccess = $strSuccess + "(" + $str + ":" + $objService.State + ")"
      }
    }
  }
  if ( $bFound -ne 1 )
  {
    $strNotFound = $strNotFound + $str + ","
  }  
}

$res = ""
if ( $strNotFound -ne "" )
{
  $strNotFound = $strNotFound.trimEnd(',')
  $res = $res + "UNCERTAIN: Not Found[" + $strNotFound + "] "
}

if ( $strFailed -ne "" )
{
  $res = $res + "ERROR: Failed[" + $strFailed + "] "
}

if ( $strSuccess -ne "" )
{
  $res = $res + "SUCCESS: [" + $strSuccess + "]"  
}

echo $res
exit