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 File Size 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 File Size check

File-CheckFileSize.ps1.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
#      FileSize.ps1
# Description:
#     Checks the file size
# Parameters:
#     1) strFileName (string)  - Path to the file to check
#     2) MaxFileSize  - Maximal file size allowed
# Usage:
#      .\FileSize.ps1 '<file> <size>' 
# Sample:
#      .\FileSize.ps1 'c:\windows\zapotec.bmp' 160
#################################################################################

# Parameters
param
  (
    [string]$strFileName,
    [int]$MaxFileSize
  )

cls

# Check paramters input
if( ([string]$strFileName -eq "") -or ($MaxFileSize -eq "") )
  {
    echo "UNCERTAIN: Invalid number of parameters - Usage: .\FileSize.ps1 <file> <max_size_KB>"
    exit
  }


#################################################################################
# THE SCRIPT ITSELF
#################################################################################

if( (Test-Path $strFileName) -eq $true )
{
  $colItems = Get-ChildItem $strFileName
  
  if(($colItems.Length / 1KB) -lt $MaxFileSize)
  {
    $succ = "SUCCESS: File size ("+ $strFileName +") = " + ($colItems.length / 1KB) + " KB, maximum allowed " + $MaxFileSize + " KB. DATA:" + ($colItems.sum / 1KB)
    echo $succ
  }
  else
  {
    $err = "ERROR: File size ("+ $strFileName +") = " + ($colItems.length / 1KB) + " KB, maximum allowed " + $MaxFileSize + " KB. DATA:" + ($colItems.sum / 1KB)
    echo $err
  }
}
else
{
  echo "UNCERTAIN: Please make sure the path is correct"
}