VBS Script To Send Basic Machine Information To Excel

 

This VBS Script will send the following information for a specified machine name to excel: Machine Name, User Name, Operating System, Build Version, Manufacturer and Model.

 

VBS Script:

 

strComputer = InputBox ("Enter Machine Name")

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

 

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

objExcel.Cells(2, 1).Value = "User Name"

objExcel.Cells(3, 1).Value = "Operating System"

objExcel.Cells(4, 1).Value = "Build Version"

objExcel.Cells(5, 1).Value = "Manufacturer"

objExcel.Cells(6, 1).Value = "Model"

 

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

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

For Each objItem in colItems

objExcel.Cells(1, 2).Value = objItem.CSName

objExcel.Cells(3, 2).Value = objItem.Manufacturer

objExcel.Cells(4, 2).Value = objItem.Version & Space(1) & objItem.CSDVersion & " Build " &  objItem.BuildNumber

objExcel.Cells(3, 2).Value = objItem.Caption

Next

 

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

For Each objItem in colItems

objExcel.Cells(2, 2).Value = objItem.UserName

objExcel.Cells(5, 2).Value = objItem.Manufacturer

objExcel.Cells(6, 2).Value = objItem.Model

Next

 

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

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

 

MsgBox "Done"

 

 

 

 

Published Monday, December 22, 2008 9:40 AM by dhite
Filed under:

Comments

No Comments