mountpoint.ps1 - powershell script by ActiveXperts Software
mountpoint.ps1 checks whether Windows Mount Point has sufficient space.
Use mountpoint.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select mountpoint.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.
mountpoint.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
# MountPoint.ps1
# Description:
# This function checks if Windows Mount Point has enough space left
# Declare Parameters:
# 1) strHost (string) - Hostname or IP address of the computer you want to monitor
# 2) strMointPoint (string) - The Windows Mount Point you want to monitor
# 3) nRequiredSpaceMB (int) - The freespace required on the Windows Mount Point in MB
# 4) 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:
# .\MountPoint.ps1 '<Hostname | IP>' '<Mount Point Path>' <Required_Space_MB> '[alt-credentials]'
# Sample:
# .\MountPoint.ps1 'localhost' 'c:\myMountPoint' 25000
#################################################################################
# -- Declare Parameters
param( [string]$strHost, [string]$strMountPoint, [int]$nRequiredSpaceMB = 0, [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()
if( $strHost -eq '' -or $strMountPoint -eq '' -or $nRequiredSpaceMB -lt 0 )
{
$res = 'UNCERTAIN: Invalid number of parameters - .\MountPoint.ps1 "<Hostname | IP>" "<Mount Point Path>" <Required Space MB> "[alt-credentials]"'
echo $res
exit
}
# Declare local variables by assigning an initial value to it
$strExplanation = ''
$objAltCredentials = $null
# 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 'getCredentials' is implemented in '_activexperts.ps1'
if( ( AxGetCredentials $strHost $strAltCredentials ([ref]$objAltCredentials) ([ref]$strExplanation) ) -ne $AXSUCCESS )
{
echo $strExplanation
exit
}
}
$strWmi = 'Win32_PerfFormattedData_PerfDisk_LogicalDisk'
if( $objAltCredentials -eq $null )
{
$objWmi = Get-WmiObject -ComputerName $strHost -Class $strWmi -ErrorVariable Error -ErrorAction SilentlyContinue
}
else
{
$objWmi = Get-WmiObject -ComputerName $strHost -Class $strWmi -Credential $objCredentials -ErrorVariable Error -ErrorAction SilentlyContinue
}
# If anything went wrong Powershell sets the error in the global array $Error
if( $Error -ne '' )
{
$res = 'UNCERTAIN: ' + $Error
echo $res
exit
}
if( $objWmi -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
}
foreach( $objDisk in $objWmi )
{
if( $objDisk.Name -eq $strMountPoint )
{
if( $nRequiredSpaceMB -le $objDisk.FreeMegaBytes )
{
$res = 'SUCCESS: '
}
else
{
$res = 'ERROR: '
}
$res += 'MountPoint[' + $strMountPoint + '] has ' + $objDisk.FreeMegabytes + 'MB free space, ' + $nRequiredSpaceMB + 'MB is required'
echo $res
exit
}
}
$res = 'UNCERTAIN: MountPoint[' + $strMountPoint + '] was not found on [' + $strHost + ']'
echo $res
exit
#################################################################################
# // --- Catch script exceptions ---
#################################################################################
trap [Exception]
{
$res = 'UNCERTAIN: ' + $_.Exception.Message
echo $res
exit
}
