The VBScript Network and Systems Administrator's Cafe

Mar 13 2009   11:05AM GMT

Writing a BGINFO like Script: Displaying Disk Statistics with WMI via the Win32_LogicalDisk class

Jerry Lees Jerry Lees Profile: Jerry Lees

I recently had to provide the information displayed with BGINFO on a number of systems. Unfortunately, BGInfo only generates a bitmap, so far as I know, so I decided to write a script to generate the information and use this displayed information to send back to the person who requested it.

The function below is a part of the script I mentioned. It retrieves and returns text that represents the total space and the total free space on all the physical hard drives in a system.

You can view all the scripts in this BGINFO series here.

Here is the code:

Function GetDiskInfo(strComputer)
Dim colItems, objItem, address
Dim StrQuery
Dim objWMIService

StrQuery = “SELECT * FROM Win32_logicaldisk”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery(strQuery,,48)
GetDiskInfo = VbCrLf

For Each objItem in colItems
if objitem.MediaType = 12 Then
GetDiskInfo = GetDiskInfo & vbTab & objItem.Caption & “\ ” & Round((((objItem.size/1024)/1024)/1024),2) & ” GB Total with ” & Round((((objItem.Freespace/1024)/1024)/1024),2) & ” GB free” & ” (” & objitem.filesystem & “)” & VbCrLf
End If
Next
End Function

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: