Created
January 11, 2017 16:01
-
-
Save flakshack/06a5fdbe6006f206ff75ace12a44ff38 to your computer and use it in GitHub Desktop.
SCOM DiskUsedGB Collection Script
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 characters
'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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script that supports Volume Mount points in addition to regular disks. To be used with directions here: https://blogs.technet.microsoft.com/mspfe/2012/04/26/how-to-monitor-disk-usage-with-system-center-operations-manager/