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 Memory-CheckCommittedMemory.ps1 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.

Screenshot of a Powershell CheckCommittedMemory check

Memory-CheckCommittedMemory.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:
#     Memory-CheckCommittedMemory.ps1
# Description: 
#     Check free memory (MB) on the computer specified by strComputer
# Parameters:
#     1) strComputer As String - Hostname or IP address of the computer you want to check
#     2) nMaxCommittedMB  As Number - Maximum allowed committed memory (in MB)
#     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:
#     .\Memory-CheckCommittedMemory.ps1 '<computer>' <Max_MB> '<alt-credentials> | <>'
# Sample:
#     .\Memory-CheckCommittedMemory.ps1 'localhost' 800 ''
#################################################################################

# Parameters
param
  (
    [string]$strComputer,
    [int]$nMaxMB,
    [string]$strAltCredentials
  )

cls

# Check paramters input
if ( ([string]$strComputer -eq "") -or ([int]$nMaxMB -eq 0) )
{
  echo "UNCERTAIN: Invalid number of parameters - Usage: .\Memory-CheckCommittedMemory.ps1 '<computer>' <Max_MB> '<alt-credentials> | <>'"
  exit
}

# Create object
if ( [string]$strAltCredentials -eq ""  )
{
  $objMem = Get-WmiObject -ComputerName $strComputer -Class Win32_PerfFormattedData_PerfOS_Memory
}
else
{
  $objNmCredentials = new-object -comobject ActiveXperts.NMServerCredentials
  $strLogin = $objNmCredentials.GetLogin( $strAltCredentials )
  $strPassword = $objNmCredentials.GetPassword( $strAltCredentials )
  
  if($strPassword -ne "") { $strPasswordSecure = ConvertTo-SecureString -string $strPassword -AsPlainText -Force }
  $objCredentials = new-object -typename System.Management.Automation.PSCredential $strLogin, $strPasswordSecure
  $objMem = Get-WmiObject -ComputerName $strComputer -Class Win32_PerfFormattedData_PerfOS_Memory -Credential $objCredentials 
}

#################################################################################
# The script itself
#################################################################################

if ( $objMem -eq $null )
{
  $res = "UNCERTAIN: Unable to connect. Please make sure that PowerShell and WMI are both installed on the monitered system. Also check your credentials"
  echo $res
  exit
}

$nCommittedMB = [math]::round(($objMem.CommittedBytes / (1024 * 1024)),0)

$nDiffMB = $nMaxMB - $nCommittedMB

if ( $nDiffMB -gt 0 )
{
  $res = "SUCCESS: "
}
else
{
  $res = "ERROR: "
}

$res = $res + "Committed memory=[" + $nCommittedMB + " MB], maximum allowed=[" + $nMaxMB + " MB]"
echo $res
exit