Menu Close

VBScript to show volume size info

Here is an example of a vbscript that will show you volume size info for C. It will display the following info:

– Computer Name/hostname
– Volume name, File System
– Free space
– Used space
– Total size

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_LogicalDisk where DeviceID=’c:'”,,48)

For Each objItem in colItems

if len(objItem.VolumeName)>0 then

Wscript.Echo “” & vbCrLf _
& “Computer Name:” & vbTab & objItem.SystemName & vbCrLf _
& “———————————————” & vbCrLf _
& “Volume Name:” & vbTab & objItem.VolumeName & ” (” & objItem.Name & “)” & ” (” & objItem.FileSystem & “)” & vbCrLf _
& “———————————————” & vbCrLf _
& “Free Space:” & vbTab _
& FormatNumber((CDbl(objItem.FreeSpace)/1024/1024/1024)) & ” (” & FormatNumber(((FormatNumber((CDbl(objItem.FreeSpace)/1024/1024/1024))) / (FormatNumber((CDbl(objItem.Size)/1024/1024/1024))) )*100,2) & “%)” & vbCrLf _
& “Used Space:” & vbTab _
& FormatNumber((CDbl(objItem.Size – objItem.FreeSpace)/1024/1024/1024)) & ” (” & FormatNumber(((FormatNumber((CDbl(objItem.Size – objItem.FreeSpace)/1024/1024/1024))) / (FormatNumber((CDbl(objItem.Size)/1024/1024/1024))) )*100,2) & “%)” & vbCrLf _
& “Total Size:” & vbTab & vbTab _
& FormatNumber((CDbl(objItem.Size)/1024/1024/1024))
‘ & objItem.Label FileSystem Name
end if
Next