Created
January 11, 2017 16:01
-
-
Save flakshack/06a5fdbe6006f206ff75ace12a44ff38 to your computer and use it in GitHub Desktop.
Revisions
-
flakshack created this gist
Jan 11, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ 'On Error Resume Next CONST GB = 1073741824 Dim oAPI, oBag Set oAPI = CreateObject("MOM.ScriptAPI") Set oArgs = WScript.Arguments drive = oArgs(0) strComputer = "." Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") ' If the drive designation is longer than 2 characters, it is a mount point. ' We have to use a different command to gather the size of a mount point. If len(drive) > 2 Then ' Append a \ on the end of the path if it is not there to match what Win32_Volume uses If right(drive, 1) <> "\" Then drive = drive & "\" End If 'The WMI query uses backslashes for escapes so we have to duplicate each drive = replace(drive, "\", "\\") Set oVolumes = oWMI.ExecQuery ("SELECT * FROM Win32_Volume Where Name= '" & drive & "'") For Each oVolume In oVolumes diskSize = CDbl(oVolume.capacity) diskFree = CDbl(oVolume.freespace) diskUsedGB = round((diskSize - diskFree)/GB, 2) Next Else Set oDisks = oWMI.ExecQuery("Select * from Win32_LogicalDisk Where DeviceID= '" & drive & "'") For each oDisk in oDisks diskSize = CDbl(oDisk.size) diskFree = CDbl(oDisk.freespace) diskUsedGB = round((diskSize - diskFree)/GB, 2) Next End If ' Return the value to SCOM Set oBag = oAPI.CreatePropertyBag() Call oBag.AddValue("DiskUsed",diskUsedGB) Call oAPI.Return(oBag)