'========================================================================== ' ' NAME: Get Logical Disk Space ' ' AUTHOR: Brian Wren , Microsoft Consulting Services ' DATE : 3/11/2003 ' ' COMMENT: Gets logical disk space using WMI. ' ' DISCLAIMER: Use of included script samples are subject to the terms ' specified at http://www.microsoft.com/info/cpyright.htm. '========================================================================== Option Explicit 'Event Constants Const EVENT_TYPE_SUCCESS = 0 Const EVENT_TYPE_ERROR = 1 Const EVENT_TYPE_WARNING = 2 Const EVENT_TYPE_INFORMATION = 4 Dim oParams Dim oWMI Dim dFreeSpacePct Dim sMessage Dim cDrives Dim oDrive Dim iWarningLevel Dim iErrorLevel Set oParams = ScriptContext.Parameters iWarningLevel = oParams.Get("WarningLevel") iErrorLevel = oParams.Get("ErrorLevel") Set oWMI = GetObject("winmgmts:\\.\root\cimv2") Set cDrives = oWMI.ExecQuery("Select * from Win32_LogicalDisk",,48) For Each oDrive in cDrives 'DriveType of 3 indicates a hard disk. If oDrive.DriveType = 3 Then If oDrive.Size > 0 Then dFreeSpacePct = oDrive.FreeSpace / oDrive.Size * 100 If CDbl(dFreeSpacePct) < CDbl(iWarningLevel) Then sMessage = oDrive.DriveType & " Drive " & oDrive.Name & " has " & dFreeSpacePct & "% free space" If CDbl(dFreeSpacePct) < CDbl(iErrorLevel) Then CreateEvent 1002,EVENT_TYPE_ERROR,sMessage Else CreateEvent 1001,EVENT_TYPE_WARNING,sMessage End If End If End If End If Next Sub CreateEvent(lngEventID, lngEventType, strMessage) Dim objNewEvent ' Create a new event Set objNewEvent = ScriptContext.CreateEvent ' Set event properties objNewEvent.Message = strMessage objNewEvent.EventNumber = lngEventID objNewEvent.EventType = lngEventType ' Submit the event ScriptContext.Submit objNewEvent Set objNewEvent = Nothing End Sub