VBS Script To Send A Remote Machines Logical Disk Information To Excel

 

This VBS Script will take a local or remote machine name from an input dialog box and will send the machine name, drive letter and disk type to an Excel spreadsheet.

 

VBS Script:

 

strComputer = InputBox("Enter Server Name")

 

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 = "Device ID"

objExcel.Cells(1, 3).Value = "Drive Type"

 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\Cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")

   

For Each objItem in colItems

objExcel.Cells(intRow, 1).Value = objItem.SystemName 

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

Select Case objItem.DriveType

Case 0 DriveType = "Unknown"

Case 1 DriveType = "No Root Directory"

Case 2 DriveType = "Removable Disk"

Case 3 DriveType = "Local Disk Drive"

Case 4 DriveType = "Network Connection"

Case 5 DriveType = "CD-ROM Disc"

Case 6 DriveType = "RAM Drive"

Case Else DriveType = ""

End Select

objExcel.Cells(intRow, 3).Value = DriveType

intRow = intRow + 1

Next

 

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

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

 

MsgBox "Done"

 

 

 

Published Sunday, October 26, 2008 2:34 PM by dhite
Filed under:

Comments

No Comments