Windows Server 2016 and above Logical Disk Free Space Data Source Module

Microsoft.Windows.Server.10.0.Legacy.LogicalDisk.FreeSpace.ModuleType (DataSourceModuleType)

Monitor the Logical Disk Free Space on Windows Server 2016 and above operating systems.

Knowledge Base article:

Summary

This module type checks the logical disk free space on Windows Server 2016.

Configuration

Here is the list of overridable parameters:

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
Scheduler DataSource System.Scheduler Default
PA ProbeAction Microsoft.Windows.Server.10.0.PowerShellPropertyBagProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval secondsHow frequently (in seconds) the value should be sampled.
TimeoutSecondsint$Config/TimeoutSeconds$Timeout SecondsNumber of seconds that the script is allowed to run before it will be forced to stop.
DebugFlagbool$Config/DebugFlag$Debug FlagThis setting enables the script to log different events at running time

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.10.0.Legacy.LogicalDisk.FreeSpace.ModuleType" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TargetComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="DebugFlag" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="DebugFlag" Selector="$Config/DebugFlag$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime/>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PA" TypeID="Microsoft.Windows.Server.10.0.PowerShellPropertyBagProbe">
<ScriptName>Microsoft.Windows.Server.Legacy.FreeSpace.ps1</ScriptName>
<PSparam>param ($TargetComputer, $DebugFlag)</PSparam>
<ScriptBody><Script>
#Copyright (c) Microsoft Corporation. All rights reserved.
#
# Parameters that should be passed to this script
# 0 Computer (FQDN)
# 1 Debug Flag - If True then script can output some trace information to event log.
# 2 System Drive Warning MBytes Threshold
# 3 System Drive Warning Percent Threshold
# 4 System Drive Error MBytes Threshold
# 5 System Drive Error Percent Threshold
# 6 Non System Drive Warning MBytes Threshold
# 7 Non System Drive Warning Percent Threshold
# 8 Non System Drive Error MBytes Threshold
# 9 Non System Drive Error Percent Threshold

$BYTES_IN_MB = 1048576 #=2^20

$DriveHealthyState = 0
$DriveWarningState = 1
$DriveErrorState = 2

Function Main()
{
$g_DebugFlag = [System.Convert]::ToBoolean($DebugFlag)

$IsNano = Is_NanoServer
$IsVolumeInfoSupported = Is_Win32_Volume_Supported $TargetComputer
$SystemDrive = Get_System_Drive $TargetComputer

$bBagIsNotEmpty = $false

$oVolumes = Get-Volumes -IsNano $IsNano -IsVolumeSupported $IsVolumeInfoSupported -TargetComputer $TargetComputer

foreach ($oVolume in $oVolumes)
{
$VolumeId = Get-VolumeId -IsNano $IsNano -IsVolumeSupported $IsVolumeInfoSupported -Volume $oVolume
if ($true -eq $IsNano)
{
$nFreeSpace = $oVolume.SizeRemaining
$nMaxSize = $oVolume.Size
}
else
{
$nFreeSpace = $oVolume.FreeSpace
if ($IsVolumeInfoSupported)
{
$nMaxSize = $oVolume.Capacity
}
else
{
$nMaxSize = $oVolume.Size
}
}

Create-PerfData -VolumeId $VolumeId -nMaxSize $nMaxSize -nFreeSpace $nFreeSpace -SystemDrive $SystemDrive -momAPI $momAPI
}

Unload-Module -ModuleName "Storage"
Unload-Module -ModuleName "CimCmdLets"
}

Function Create-PerfData([string]$VolumeId,$nMaxSize,$nFreeSpace,[string]$SystemDrive,$momAPI)
{
$ErrorActionPreference="SilentlyContinue"
$error.Clear()

if ($null -eq $momAPI)
{
return
}

if ($nMaxSize -eq $null -or $nMaxSize -eq 0)
{
return
}

if ($nFreeSpace -eq $null)
{
$nFreeSpace = 0
}

$nPctFree = [math]::Round($nFreeSpace / $nMaxSize * 100, 2)
$nMBFree = [math]::Round($nFreeSpace / $BYTES_IN_MB, 0)

$oBag = $momAPI.CreatePropertyBag()
$oBag.AddValue("PctFree", [string]$nPctFree)
$oBag.AddValue("MbFree", [string]$nMbFree)
$oBag.AddValue("DiskLabel", $VolumeId)
if ($VolumeId -ieq $SystemDrive)
{
$oBag.AddValue("IsSystem", "true")
}
else
{
$oBag.AddValue("IsSystem", "false")
}

if ($error.Count -eq 0)
{
$oBag
}
}

Main

</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>TargetComputer</Name>
<Value>$Config/TargetComputerName$</Value>
</Parameter>
<Parameter>
<Name>DebugFlag</Name>
<Value>$Config/DebugFlag$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PA">
<Node ID="Scheduler"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>