Saturday, April 10, 2010

VBScript - Retrieve Computer Information from an Excel Spreadsheet

VBScript - Retrieve Computer Information from an Excel Spreadsheet (Retrieves data from Excel spreadsheet and echoes it to the screen)

Dim xlApp, xlBook, xlWks
Dim intRow

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\scripts\ServerList.xls")
Set xlWks = xlBook.Worksheets(1)
'xlApp.Visible=True
xlWks.Activate

intRow=1

Do Until xlApp.Cells(intRow,1).Value = ""

WScript.Echo "ServerName: " & xlApp.Cells(intRow, 1).Value & "," & " IP Address: " & xlApp.Cells(intRow, 2).Value _
& "," & " 2nd IP Address: " & xlApp.Cells(intRow, 3).Value & "," & " Rack: " & xlApp.Cells(intRow, 6).Value _
& "," & " Applications: " & xlApp.Cells(intRow, 7).Value & "," & " Operating System: " & xlApp.Cells(intRow, 4).Value _
& "," & " Domain: " & xlApp.Cells(intRow, 15).Value
WScript.Echo "ServerName: " & xlApp.Cells(intRow, 1).Value & "," & " Hardware: " & xlApp.Cells(intRow, 21).Value _
& "," & " Serial Number: " & xlApp.Cells(intRow, 26).Value & "," & " CPU: " & xlApp.Cells(intRow, 20).Value _
& "," & " Memory: " & xlApp.Cells(intRow, 19).Value
intRow = intRow+1

Loop

xlBook.Close True
xlApp.Quit
Set xlWks=Nothing
Set xlBook=Nothing
Set xlApp=Nothing

[Via]