Windows 10 and above Logical Disk Monitor Type

Microsoft.Windows.Client.Win10.LogicalDisk.Monitortype (UnitMonitorType)

Element properties:

RunAsSystem.PrivilegedMonitoringAccount
AccessibilityInternal
Support Monitor RecalculateTrue

Member Modules:

ID Module Type TypeId RunAs 
DS1 DataSource System.Scheduler Default
PassThrough ProbeAction System.PassThroughProbe Default
Script ProbeAction System.CommandExecuterProbePropertyBagBase Default
FilterNotOK ConditionDetection System.ExpressionFilter Default
FilterOK ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval (seconds)
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds

Source Code:

<UnitMonitorType ID="Microsoft.Windows.Client.Win10.LogicalDisk.Monitortype" RunAs="System!System.PrivilegedMonitoringAccount" Accessibility="Internal">
<MonitorTypeStates>
<MonitorTypeState ID="Good"/>
<MonitorTypeState ID="Bad"/>
</MonitorTypeStates>
<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="DiskLabel" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource TypeID="System!System.Scheduler" ID="DS1">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ProbeAction TypeID="System!System.CommandExecuterProbePropertyBagBase" ID="Script">
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/Microsoft.Windows.Client10.LogicalDiskHealthCheck.vbs$ $Config/TargetComputerName$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>Microsoft.Windows.Client10.LogicalDiskHealthCheck.vbs</Name>
<Contents><Script>'Copyright (c) Microsoft Corporation. All rights reserved.

'*************************************************************************
' $ScriptName: "Microsoft.Windows.Client10.Common"$
'
' Purpose: To have one place for common stuff across various BaseOS VBScripts
'
' $File: Microsoft.Windows.Client10.Common.vbs$
'*************************************************************************

Option Explicit

SetLocale("en-us")

' LogScripEvent Constants
Const lsEventError = 1
Const lsEventWarning = 2
Const lsEventInformation = 3

' WMI Constants
Const wbemCimtypeUseDefault = 0 'Use Default Type CIM type - Custom
Const wbemCimtypeSint16 = 2 'Signed 16-bit integer
Const wbemCimtypeSint32 = 3 'Signed 32-bit integer
Const wbemCimtypeReal32 = 4 '32-bit real number
Const wbemCimtypeReal64 = 5 '64-bit real number
Const wbemCimtypeString = 8 'String
Const wbemCimtypeBoolean = 11 'Boolean value
Const wbemCimtypeObject = 13 'CIM object
Const wbemCimtypeSint8 = 16 'Signed 8-bit integer
Const wbemCimtypeUint8 = 17 'Unsigned 8-bit integer
Const wbemCimtypeUint16 = 18 'Unsigned 16-bit integer
Const wbemCimtypeUint32 = 19 'Unsigned 32-bit integer
Const wbemCimtypeSint64 = 20 'Signed 64-bit integer
Const wbemCimtypeUint64 = 21 'Unsigned 64-bit integer
Const wbemCimtypeDatetime = 101 'Date/time value
Const wbemCimtypeReference = 102 'Reference to a CIM object
Const wbemCimtypeChar16 = 103 '16-bit character

Const ErrAction_None = 0
Const ErrAction_Trace = 1
Const ErrAction_ThrowError = 16
Const ErrAction_Abort = 32
Const ErrAction_ThrowErrorAndAbort = 48
Dim g_DebugFlag

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

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 WMIGetInstanceNoAbort(ByVal sNamespace, ByVal sInstance)
'
' WMIGetInstanceNoAbort :: Returns WMI Instance requested.
'
'
Dim oWMI, oInstance, nInstanceCount

On Error Resume Next
Set oWMI = GetObject(sNamespace)
If Not IsEmpty(oWMI) Then

Set oInstance = oWMI.InstancesOf(sInstance)
If Not IsEmpty(oInstance) And Err.Number = 0 Then

'Determine if we queried a valid WMI class - Count will return 0 or empty
nInstanceCount = oInstance.Count
If Err.Number = 0 Then
Set WMIGetInstanceNoAbort = oInstance
Exit Function
End If
End If
End If
On Error Goto 0

Set WMIGetInstanceNoAbort = Nothing

End Function

Function GetWMIProperty(oWmi, sPropName, nCIMType, ErrAction)
Dim sValue, oWmiProp

If Not IsValidObject(oWmi) Then
If (ErrAction And ErrAction_ThrowError) = ErrAction_ThrowError Then _
ThrowScriptErrorNoAbort "Accessing property on invalid WMI object.", Err

If (ErrAction And ErrAction_Abort) = ErrAction_Abort Then _
Quit()

GetWMIProperty = ""
Exit Function
End If

On Error Resume Next
Set oWmiProp = oWmi.Properties_.Item(sPropName)
If Err.Number &lt;&gt; 0 Then
If (ErrAction And ErrAction_ThrowError) = ErrAction_ThrowError Then _
ThrowScriptErrorNoAbort "An error occurred while accessing WMI property: '" &amp; sPropName &amp; "'.", Err

If (ErrAction And ErrAction_Abort) = ErrAction_Abort Then _
Quit()
End If
On Error Goto 0

If IsValidObject(oWmiProp) Then
sValue = oWmiProp.Value

If IsNull(sValue) Then
'
' If value is null, return blank to avoid any issues
'
GetWMIProperty = ""

Else

Select Case (oWmiProp.CIMType)
Case wbemCimtypeString, wbemCimtypeSint16, wbemCimtypeSint32, wbemCimtypeReal32, wbemCimtypeReal64, wbemCimtypeSint8, wbemCimtypeUint8, wbemCimtypeUint16, wbemCimtypeUint32, wbemCimtypeSint64, wbemCimtypeUint64:
If Not oWmiProp.IsArray Then
GetWMIProperty = Trim(CStr(sValue))
Else
GetWMIProperty = Join(sValue, ", ")
End If
Case wbemCimtypeBoolean:
If sValue = 1 Or UCase(sValue) = "TRUE" Then
GetWMIProperty = "True"
Else
GetWMIProperty = "False"
End If
Case wbemCimtypeDatetime:

Dim sTmpStrDate

'
' First attempt to convert the whole wmi date string
'
sTmpStrDate = Mid(sValue, 5, 2) &amp; "/" &amp; _
Mid(sValue, 7, 2) &amp; "/" &amp; _
Left(sValue, 4) &amp; " " &amp; _
Mid (sValue, 9, 2) &amp; ":" &amp; _
Mid(sValue, 11, 2) &amp; ":" &amp; _
Mid(sValue, 13, 2)
If IsDate(sTmpStrDate) Then
GetWMIProperty = CDate(sTmpStrDate)
Else

'
' Second, attempt just to convert the YYYYMMDD
'
sTmpStrDate = Mid(sValue, 5, 2) &amp; "/" &amp; _
Mid(sValue, 7, 2) &amp; "/" &amp; _
Left(sValue, 4)
If IsDate(sTmpStrDate) Then
GetWMIProperty = CDate(sTmpStrDate)
Else
'
' Nothing works - return passed in string
'
GetWMIProperty = sValue
End If

End If

Case Else:
GetWMIProperty = ""
End Select
End If
Else

If (ErrAction And ErrAction_ThrowError) = ErrAction_ThrowError Then _
ThrowScriptErrorNoAbort "An error occurred while accessing WMI property: '" &amp; sPropName &amp; "'.", Err

If (ErrAction And ErrAction_Abort) = ErrAction_Abort Then _
Quit()

GetWMIProperty = ""

End If


If (ErrAction And ErrAction_Trace) = ErrAction_Trace Then _
WScript.Echo " + " &amp; sPropName &amp; " :: '" &amp; GetWMIProperty &amp; "'"

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 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
On Error Resume Next


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 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 GetPerfmonInstance(ByVal sName)
sName = Replace(sName,"(","[")
sName = Replace(sName,")","]")
sName = Replace(sName,"/","_")
sName = Replace(sName,"#","_")
GetPerfmonInstance = sName
End Function

Function GetPerfmonInstance(ByVal sTargetComputer, ByVal sDeviceID, ByVal sIndex)
Dim owObj, owObj2, oWMISet, oWMISet2, sPerfInstance
Dim sTemp
sPerfInstance = ""
Set oWMISet = WMIExecQuery("winmgmts:\\" + sTargetComputer + "\root\cimv2", "associators of {win32_diskdrive='" &amp; sDeviceID &amp;"'} where ResultClass=win32_diskpartition")
For each owObj in oWMISet
sTemp = GetWMIProperty(owObj, "DeviceID", wbemCimtypeUseDefault, ErrAction_Abort)
Set oWMISet2= WMIExecQuery("winmgmts:\\" + sTargetComputer + "\root\cimv2", "associators of {win32_diskpartition='" &amp; sTemp &amp; "'} where ResultClass=win32_logicaldisk")
For each owObj2 in oWMISet2
sTemp = GetWMIProperty(owObj2, "DeviceID", wbemCimtypeUseDefault, ErrAction_Abort)
If sPerfInstance = "" Then
sPerfInstance = sPerfInstance + sTemp
Else
sPerfInstance = sPerfInstance + " " + sTemp
End If
Next
Next
GetPerfmonInstance = sIndex &amp; " " &amp; sPerfInstance
End Function

Function Quit()

WScript.Quit()

End Function

Sub CreateEvent(oAPI, lEventID, lEventType, strMessage)
'
' Purpose: To generate a MOM event
'
' Arguments: lEventID, the event code
' lEventType, the severity of the event
' strMessage, the message to include in the event
'
On Error Resume Next

oAPI.LogScriptEvent "Base OS Client", lEventID, lEventType, strMessage
End Sub

'---------------------------------------------------------------------------
' Outputs arguments for debugging purposes
'---------------------------------------------------------------------------
Function TraceLogArguments
Dim oArgs
Set oArgs = WScript.Arguments
Dim i, sArgs
For i = 0 To oArgs.Count - 1
sArgs = sArgs &amp; " {" &amp; oArgs(i) &amp; "}"
Next
TraceLogMessage "Arguments:" &amp; sArgs
End Function

'---------------------------------------------------------------------------
' Verifies that number of arguments is correct
'---------------------------------------------------------------------------
Function VerifyNumberOfArguments(ByVal NumberOfArguments)
Dim oArgs
Set oArgs = WScript.Arguments
If oArgs.Count &lt;&gt; NumberOfArguments Then
Dim i, sArgs
For i = 0 To oArgs.Count - 1
sArgs = sArgs &amp; " {" &amp; oArgs(i) &amp; "}"
Next
ThrowScriptError "Invalid number of arguments (" &amp; oArgs.Count &amp; " instead of " &amp; NumberOfArguments &amp; "). Arguments:" &amp; sArgs, Null
End If
End Function

'---------------------------------------------------------------------------
' Outputs to file and echo for debugging purposes
'---------------------------------------------------------------------------
Function TraceLogMessage(ByVal sMessage)
WScript.Echo sMessage

If g_DebugFlag = True Then
' Retrieve the name of this (running) script
Dim FSO, ScriptFileName
Set FSO = CreateObject("Scripting.FileSystemObject")
ScriptFileName = FSO.GetFile(WScript.ScriptFullName).Name
Set FSO = Nothing

On Error Resume Next
Dim oAPITemp
Set oAPITemp = MOMCreateObject("MOM.ScriptAPI")
oAPITemp.LogScriptEvent ScriptFileName, g_TraceEventNumber, lsEventInformation, sMessage
On Error Goto 0
End If
End Function

'---------------------------------------------------------------------------
' Verifies the expression. If equals to False then generates an error and quits the script
' Usage:
' Verify Not WMISet Is Nothing, "WMISet is invalid!"
' Verify WMISet.Count = 1, "Invalid quantity of services with name 'Server' (qty = " &amp; WMISet.Count &amp; ")."
'---------------------------------------------------------------------------
Function Verify(ByVal bBool, ByVal sMessage)
If bBool = False Then
ThrowScriptError sMessage, Null
End If
End Function


'Copyright (c) Microsoft Corporation. All rights reserved.

' Parameters that should be passed to this script
' 0 Computer (FQDN)

SetLocale("en-us")

Call Main

Sub Main()
VerifyNumberOfArguments(1)

Dim oArgs
Set oArgs = WScript.Arguments
Dim TargetComputer
TargetComputer = oArgs(0)

Dim oAPI, oBag
Set oAPI = MOMCreateObject("MOM.ScriptAPI")

Dim IsVolumeInfoSupported
IsVolumeInfoSupported = Is_Win32_Volume_Supported(TargetComputer)

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

For Each oWmiDisk in oWmiDiskSet
Dim sDriveLetter
If IsVolumeInfoSupported Then
sDriveLetter = oWmiDisk.DriveLetter
If IsNull(sDriveLetter) Then
sDriveLetter = oWmiDisk.Name
sDriveLetter = Left(sDriveLetter, Len(sDriveLetter) - 1)
End If
Else
sDriveLetter = oWmiDisk.DeviceId
End If

If (Not IsNull(sDriveLetter)) And (Not IsEmpty(sDriveLetter)) Then
Dim DirtyBitSet
If IsVolumeInfoSupported Then
DirtyBitSet = oWmiDisk.DirtyBitSet
Else
DirtyBitSet = oWmiDisk.VolumeDirty
End If
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue "DiskLabel", sDriveLetter
If IsNull(DirtyBitSet) Then
oBag.AddValue "State", "OK"
Else
If DirtyBitSet = True Then
oBag.AddValue "State", "BAD"
Else
oBag.AddValue "State", "OK"
End If
End If
oAPI.AddItem oBag
End If
Next

oAPI.ReturnItems
End Sub

Function Is_Win32_Volume_Supported(ByRef TargetComputer)
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;= 8650 Then blnRet = True
Next
Is_Win32_Volume_Supported = blnRet
End Function

</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
<OutputType>System.PropertyBagData</OutputType>
</ProbeAction>
<ConditionDetection ID="FilterOK" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<RegExExpression>
<ValueExpression>
<XPathQuery>Property[@Name='State']</XPathQuery>
</ValueExpression>
<Operator>ContainsSubstring</Operator>
<Pattern>OK</Pattern>
</RegExExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='DiskLabel']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/DiskLabel$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
<ConditionDetection ID="FilterNotOK" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<RegExExpression>
<ValueExpression>
<XPathQuery>Property[@Name='State']</XPathQuery>
</ValueExpression>
<Operator>ContainsSubstring</Operator>
<Pattern>BAD</Pattern>
</RegExExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='DiskLabel']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/DiskLabel$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="Good">
<Node ID="FilterOK">
<Node ID="Script">
<Node ID="DS1"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="Bad">
<Node ID="FilterNotOK">
<Node ID="Script">
<Node ID="DS1"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
<OnDemandDetections>
<OnDemandDetection MonitorTypeStateID="Good">
<Node ID="FilterOK">
<Node ID="Script">
<Node ID="PassThrough"/>
</Node>
</Node>
</OnDemandDetection>
<OnDemandDetection MonitorTypeStateID="Bad">
<Node ID="FilterNotOK">
<Node ID="Script">
<Node ID="PassThrough"/>
</Node>
</Node>
</OnDemandDetection>
</OnDemandDetections>
</MonitorImplementation>
</UnitMonitorType>