Windows Logical Disk Free Space Data Source Module

Microsoft.Windows.Client.XP.FreeSpace.ModuleType (DataSourceModuleType)

Windows Memory Available MBytes Data Source Module

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval Seconds
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds
SystemDriveErrorPercentThresholddouble$Config/SystemDriveErrorPercentThreshold$System Drive Error Percent Threshold
SystemDriveWarningPercentThresholddouble$Config/SystemDriveWarningPercentThreshold$System Drive Warning Percent Threshold
NonSystemDriveErrorPercentThresholddouble$Config/NonSystemDriveErrorPercentThreshold$Non System Drive Error Percent Threshold
NonSystemDriveWarningPercentThresholddouble$Config/NonSystemDriveWarningPercentThreshold$Non System Drive Warning Percent Threshold
SystemDriveErrorMBytesThresholddouble$Config/SystemDriveErrorMBytesThreshold$System Drive Error M Bytes Threshold
SystemDriveWarningMBytesThresholddouble$Config/SystemDriveWarningMBytesThreshold$System Drive Warning M Bytes Threshold
NonSystemDriveErrorMBytesThresholddouble$Config/NonSystemDriveErrorMBytesThreshold$Non System Drive Error M Bytes Threshold
NonSystemDriveWarningMBytesThresholddouble$Config/NonSystemDriveWarningMBytesThreshold$Non System Drive Warning M Bytes Threshold

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Client.XP.FreeSpace.ModuleType" Accessibility="Internal">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SystemDriveErrorPercentThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SystemDriveWarningPercentThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NonSystemDriveErrorPercentThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NonSystemDriveWarningPercentThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SystemDriveErrorMBytesThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SystemDriveWarningMBytesThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NonSystemDriveErrorMBytesThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NonSystemDriveWarningMBytesThreshold" type="xsd:double"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="DiskLabel" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
<OverrideableParameter ID="SystemDriveErrorPercentThreshold" Selector="$Config/SystemDriveErrorPercentThreshold$" ParameterType="double"/>
<OverrideableParameter ID="SystemDriveWarningPercentThreshold" Selector="$Config/SystemDriveWarningPercentThreshold$" ParameterType="double"/>
<OverrideableParameter ID="NonSystemDriveErrorPercentThreshold" Selector="$Config/NonSystemDriveErrorPercentThreshold$" ParameterType="double"/>
<OverrideableParameter ID="NonSystemDriveWarningPercentThreshold" Selector="$Config/NonSystemDriveWarningPercentThreshold$" ParameterType="double"/>
<OverrideableParameter ID="SystemDriveErrorMBytesThreshold" Selector="$Config/SystemDriveErrorMBytesThreshold$" ParameterType="double"/>
<OverrideableParameter ID="SystemDriveWarningMBytesThreshold" Selector="$Config/SystemDriveWarningMBytesThreshold$" ParameterType="double"/>
<OverrideableParameter ID="NonSystemDriveErrorMBytesThreshold" Selector="$Config/NonSystemDriveErrorMBytesThreshold$" ParameterType="double"/>
<OverrideableParameter ID="NonSystemDriveWarningMBytesThreshold" Selector="$Config/NonSystemDriveWarningMBytesThreshold$" ParameterType="double"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/FreeSpace.vbs$ $Config/SystemDriveErrorPercentThreshold$ $Config/SystemDriveWarningPercentThreshold$ $Config/NonSystemDriveErrorPercentThreshold$ $Config/NonSystemDriveWarningPercentThreshold$ $Config/SystemDriveErrorMBytesThreshold$ $Config/SystemDriveWarningMBytesThreshold$ $Config/NonSystemDriveErrorMBytesThreshold$ $Config/NonSystemDriveWarningMBytesThreshold$ $Config/TargetComputerName$ $Config/DiskLabel$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>FreeSpace.vbs</Name>
<Contents><Script>'Copyright (c) Microsoft Corporation. All rights reserved.


Option Explicit

Dim TargetComputer

Const BYTES_IN_MB = 1048576 '=2^20
Const LOCAL = 3


Call Main

Sub Main()

Dim THRESHOLD_PCT_RED
Dim THRESHOLD_PCT_YELLOW
Dim THRESHOLD_SYSTEM_PCT_RED
Dim THRESHOLD_SYSTEM_PCT_YELLOW
Dim THRESHOLD_MB_RED
Dim THRESHOLD_MB_YELLOW
Dim THRESHOLD_SYSTEM_MB_RED
Dim THRESHOLD_SYSTEM_MB_YELLOW
Dim DiskLabel

Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count &lt;&gt; 10 Then
WScript.Quit
End If

THRESHOLD_SYSTEM_PCT_RED = oArgs(0)
THRESHOLD_SYSTEM_PCT_YELLOW = oArgs(1)
THRESHOLD_PCT_RED = oArgs(2)
THRESHOLD_PCT_YELLOW = oArgs(3)
THRESHOLD_SYSTEM_MB_RED = oArgs(4)
THRESHOLD_SYSTEM_MB_YELLOW = oArgs(5)
THRESHOLD_MB_RED = oArgs(6)
THRESHOLD_MB_YELLOW = oArgs(7)
TargetComputer = oArgs(8)
DiskLabel = oArgs(9)

Dim oAPI, oBag
Set oAPI = MOMCreateObject("MOM.ScriptAPI")
If Err.number &lt;&gt; 0 Or IsNull(oAPI) or IsEmpty(oAPI) Then
ThrowScriptError "Error While Creating ScriptAPI object", Err
Exit Sub
End If
set oBag = oAPI.CreatePropertyBag()
If Err.number &lt;&gt; 0 Or IsNull(oBag) or IsEmpty(oBag) Then
ThrowScriptError "Error While Creating PropertyBag object", Err
Exit Sub
End If

Dim IsVolumeInfoSupported

IsVolumeInfoSupported = Is_Win32_Volume_Supported()

Dim oWmiDiskSet, oWmiDisk

If IsVolumeInfoSupported Then
Set oWmiDiskSet = WMIGetInstance("winmgmts:\\" + TargetComputer &amp; "\root\cimv2", "Win32_Volume")
Else
Set oWmiDiskSet = WMIExecQuery("winmgmts:\\" + TargetComputer &amp; "\root\cimv2", "select * from Win32_LogicalDisk where (DriveType=3 or DriveType=6) and FileSystem!=null")
End If

If IsObject(oWmiDiskSet) Then
For Each oWmiDisk in oWmiDiskSet
'WScript.echo "Disk is " &amp; oWmiDisk.DriveLetter
If oWmiDisk.DriveType = LOCAL Then
Dim sDriveLetter, nFreeSpace, nMaxSize, nPctFree, nMBFree
' Calculate Free Space
nFreeSpace = oWmiDisk.FreeSpace
'WScript.echo "Disk is " &amp; oWmiDisk.DriveLetter &amp; "Free Space is " &amp; nFreeSpace

If IsNull(nFreeSpace) Then _
nFreeSpace = 0

If IsVolumeInfoSupported Then
sDriveLetter = oWmiDisk.DriveLetter
nMaxSize = oWmiDisk.Capacity
If IsNull(sDriveLetter) Then
sDriveLetter = oWmiDisk.Name
sDriveLetter = Left(sDriveLetter, Len(sDriveLetter)-1)
End If
Else
sDriveLetter = oWmiDisk.DeviceId
nMaxSize = oWmiDisk.Size
End If

If StrComp(DiskLabel,sDriveLetter) = 0 Then
If Not IsNull(nMaxSize) And nMaxSize &gt; 0 Then
'
' Drive is formatted - if we dont get a maxsize, dont report on drive
'
nPctFree = Round(nFreeSpace / nMaxSize * 100, 0)

nMBFree = Round(nFreeSpace / BYTES_IN_MB, 0)

If nPctFree &lt; CInt(THRESHOLD_SYSTEM_PCT_RED) And nMBFree &lt; CLng(THRESHOLD_SYSTEM_MB_RED) And Is_System_Drive(sDriveLetter) Then
oBag.AddValue "State", "BAD"
ElseIf nPctFree &lt; CInt(THRESHOLD_SYSTEM_PCT_YELLOW) And nMBFree &lt; CLng(THRESHOLD_SYSTEM_MB_YELLOW) And Is_System_Drive(sDriveLetter) Then
oBag.AddValue "State", "WARNING"
ElseIf nPctFree &lt; CInt(THRESHOLD_PCT_RED) And nMBFree &lt; CLng(THRESHOLD_MB_RED) And Not Is_System_Drive(sDriveLetter) Then
oBag.AddValue "State", "BAD"
ElseIf nPctFree &lt; CInt(THRESHOLD_PCT_YELLOW) And nMBFree &lt; CLng(THRESHOLD_MB_Yellow) And Not Is_System_Drive(sDriveLetter) Then
oBag.AddValue "State", "WARNING"
Else
oBag.AddValue "State", "OK"
End If
oBag.AddValue "PctFree", nPctFree &amp; ""
oBag.AddValue "MBFree", nMBFree &amp; ""
oAPI.AddItem oBag
oAPI.ReturnItems
Exit Sub
Else
'
' If the MaxSize is 0 or less, then the drive is unformatted.
' Do not report on unformatted drives
'
WScript.echo "Drive not formatted " &amp; sDriveLetter
ThrowScriptError " * " &amp; sDriveLetter &amp; " + Drive not formatted." , Err
Exit Sub
End If ' Is Null Check
End If ' Lable Check
End If ' Drive Type
Next
End If
End Sub

Function ThrowScriptErrorNoAbort(ByVal sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
'

Dim sErrDescription, sErrNumber
sErrDescription = oErr.Description
sErrNumber = oErr.Number
Wscript.echo "Error Message is " &amp; sErrDescription &amp; " Error number is " &amp; sErrNumber
End Function

Function ThrowScriptError(Byval sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
'
On Error Resume Next
ThrowScriptErrorNoAbort sMessage, oErr
Quit()
End Function


Function WMIGetObject(ByVal sNamespace)
'
' WMIGetObject :: Returns the WMI object requested.
'
'
Dim oWMI
Dim e
Set e = New Error
On Error Resume Next
Set oWMI = GetObject(sNamespace)
e.Save
On Error Goto 0
If IsEmpty(oWMI) Then
ThrowScriptError "Unable to open WMI Namespace '" &amp; sNamespace &amp; "'. Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.", e
End If

Set WMIGetObject = oWMI

End Function



Function WMIGetInstance(ByVal sNamespace, ByVal sInstance)
'
' WMIGetInstance :: Returns WMI Instance requested.
'
'
Dim oWMI, oInstance, nInstanceCount
Dim e
Set e = New Error
On Error Resume Next
Set oWMI = GetObject(sNamespace)
e.Save
On Error Goto 0
If IsEmpty(oWMI) Then
ThrowScriptError "Unable to open WMI Namespace '" &amp; sNamespace &amp; "'. Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.", e
End If

On Error Resume Next
Set oInstance = oWMI.InstancesOf(sInstance)
e.Save
On Error Goto 0
If IsEmpty(oInstance) Or e.Number &lt;&gt; 0 Then
ThrowScriptError "The class name '" &amp; sInstance &amp; "' returned no instances. Please check to see if this is a valid WMI class name.", e
End If

'Determine if we queried a valid WMI class - Count will return 0 or empty

On Error Resume Next
nInstanceCount = oInstance.Count
e.Save
On Error Goto 0
If e.Number &lt;&gt; 0 Then
ThrowScriptError "The class name '" &amp; sInstance &amp; "' did not return any valid instances. Please check to see if this is a valid WMI class name.", e
End If

Set WMIGetInstance = oInstance

End Function

Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile
Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub
Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = m_lNumber
End Property
Public Property Get Source()
Source = m_sSource
End Property
Public Property Get Description()
Description = m_sDescription
End Property
Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property
End Class

Function MomCreateObject(ByVal sProgramId)
Dim oError
Set oError = New Error

On Error Resume Next
Set MomCreateObject = CreateObject(sProgramId)
oError.Save
On Error Goto 0

If oError.Number &lt;&gt; 0 Then ThrowScriptError "Unable to create automation object '" &amp; sProgramId &amp; "'", oError
End Function

Function IsValidObject(ByVal oObject)
IsValidObject = False

If IsObject(oObject) Then
If Not oObject Is Nothing Then
IsValidObject = True
End If
End If
End Function

Function WMIExecQuery(ByVal sNamespace, ByVal sQuery)
'
' WMIExecQuery :: Executes the WMI query and returns the result set.
'
'
Dim oWMI, oQuery, nInstanceCount
Dim e
Set e = New Error
On Error Resume Next
Set oWMI = GetObject(sNamespace)
e.Save
On Error Goto 0
If IsEmpty(oWMI) Then
ThrowScriptError "Unable to open WMI Namespace '" &amp; sNamespace &amp; "'. Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.", e
End If

On Error Resume Next
Set oQuery = oWMI.ExecQuery(sQuery)
e.Save
On Error Goto 0
If IsEmpty(oQuery) Or e.Number &lt;&gt; 0 Then
ThrowScriptError "The Query '" &amp; sQuery &amp; "' returned an invalid result set. Please check to see if this is a valid WMI Query.", e
End If

'Determine if we queried a valid WMI class - Count will return 0 or empty
On Error Resume Next
nInstanceCount = oQuery.Count
e.Save
On Error Goto 0
If e.Number &lt;&gt; 0 Then
ThrowScriptError "The Query '" &amp; sQuery &amp; "' did not return any valid instances. Please check to see if this is a valid WMI Query.", e
End If

Set WMIExecQuery = oQuery

End Function


Function Is_Win32_Volume_Supported()
Dim objWMISet, objWMIOS, blnRet

blnRet = False
Set objWMISet = WMIGetInstance("winmgmts:\\" &amp; TargetComputer &amp; "\root\cimv2", "Win32_OperatingSystem")
For each objWMIOS in objWMISet
If CLng(objWMIOS.BuildNumber) &gt;= 3624 Then blnRet = True
Next
Is_Win32_Volume_Supported = blnRet
End Function

Function Is_System_Drive(sDriveLetter)
Dim objWMISet, objWMIOS
Is_System_Drive = False

Set objWMISet = WMIGetInstance("winmgmts:\\" &amp; TargetComputer &amp; "\root\cimv2", "Win32_OperatingSystem")
For each objWMIOS in objWMISet
Dim sSystemDrive
sSystemDrive = Left(objWMIOS.SystemDirectory, 2)
If sSystemDrive = sDriveLetter Then
Is_System_Drive = True
End If
Next
End Function</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>