VBS Script To Return Logical Disk Information For A List Of Machines

 

This VBS script will read the machine names from a text file called MachineList.Txt and return the machines Logical Disk information and send the results to an Excel spreadsheet.

 

The information will include the following: Machine Name, Drive letter, Total Size, Used Space, Free Space and Free Space Percentage.

 

VBS Script:

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

objExcel.Cells(1, 1).Value = "Machine Name"

objExcel.Cells(1, 2).Value = "Drive"

objExcel.Cells(1, 3).Value = "Total Size"

objExcel.Cells(1, 4).Value = "Used Space"

objExcel.Cells(1, 5).Value = "Free Space"

objExcel.Cells(1, 6).Value = "Free Space Percentage"

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("MachineList.txt", 1)

 

Do Until objFile.AtEndOfStream

strComputer = objFile.ReadLine

Set objWMIService = GetObject("winmgmts://" & strComputer)

 

On Error Resume Next

Set colDisks = objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where DriveType = 3")

For Each objDisk In colDisks

objExcel.Cells(intRow, 1).Value = Ucase(strComputer)

objExcel.Cells(intRow, 2).Value = objDisk.DeviceID

objExcel.Cells(intRow, 3).Value = (FormatNumber(objDisk.Size/ 1024^3, 1)) & " GB"

objExcel.Cells(intRow, 4).Value = (FormatNumber(objDisk.Size/ 1024^3, 1) - FormatNumber(objDisk.FreeSpace/ 1024^3, 1)) & " GB"

objExcel.Cells(intRow, 5).Value = (FormatNumber(objDisk.FreeSpace/ 1024^3, 1)) & " GB"

objExcel.Cells(intRow, 6).Value = FormatPercent(objDisk.FreeSpace/objDisk.Size, 0)

 

If FormatPercent(objDisk.FreeSpace/objDisk.Size, 0) <= "25%" Then

objExcel.Cells(intRow, 6).Font.ColorIndex = 3

Else

End If

 

intRow = intRow + 1

Next

Loop

 

objExcel.Range("A1:F1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

 

MsgBox "Done"

 

Published Sunday, July 29, 2007 2:06 PM by dhite
Filed under:

Comments

No Comments