Monitor the Logical Disk Free Space on Windows Server 2016 and above operating systems.
This module type checks the logical disk free space on Windows Server 2016.
Here is the list of overridable parameters:
Interval Seconds: How frequently (in seconds) the value should be sampled.
Timeout Seconds: Number of seconds that the script is allowed to run before it will be forced to stop.
Debug Flag: This setting enables the script to log different events at running time
Type | DataSourceModuleType |
Isolation | Any |
Accessibility | Public |
RunAs | Default |
OutputType | System.PropertyBagData |
ID | Module Type | TypeId | RunAs |
---|---|---|---|
Scheduler | DataSource | System.Scheduler | Default |
PA | ProbeAction | Microsoft.Windows.Server.10.0.PowerShellPropertyBagProbe | Default |
ID | ParameterType | Selector | Display Name | Description |
---|---|---|---|---|
IntervalSeconds | int | $Config/IntervalSeconds$ | Interval seconds | How frequently (in seconds) the value should be sampled. |
TimeoutSeconds | int | $Config/TimeoutSeconds$ | Timeout Seconds | Number of seconds that the script is allowed to run before it will be forced to stop. |
DebugFlag | bool | $Config/DebugFlag$ | Debug Flag | This setting enables the script to log different events at running time |
<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>
#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
</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>