WMI: Free disk space check
I was going though some of my scripts, and came across one that I need to add to my computer inventory script as a function. What it does is report the amount of free disk space on the machine's partitions. As I go through and update the inventory script, breaking code out into functions, I plan to add this.
Const MegabyteConversion = 1048576
Set objWMIService = GetObject("winmgmts:")
'Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
Set colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk")
If colLogicalDisk.Count = 0 Then
Wscript.Echo "No drives exist on this computer."
Else
For Each objLogicalDisk in colLogicalDisk
FreeMegaBytes = objLogicalDisk.Freespace / MegabyteConversion
FreeMegaBytes_String = Int(FreeMegaBytes) & " MB Free"
Wscript.Echo objLogicalDisk.DeviceID & " " & FreeMegaBytes_String
Next
End If
No comments:
Post a Comment