This VBS script will take a list of machine names from a text file called MachineList.Txt and will send the following information to an Excel spreadsheet taken from the “All Systems” Collection: Machine Name, Resource ID, Site Code and Domain name.
VBS Script:
On Error Resume Next
strComputer = InputBox ("Enter SMS Server Name")
strSiteCode = InputBox ("Enter Site Code")
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 = "Resource ID"
objExcel.Cells(1, 3).Value = "Site Code"
objExcel.Cells(1, 4).Value = "Domain"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
Set objWMIService = GetObject("winmgmts://" & strComputer & "\root\sms\site_" & strSiteCode)
Set colItems = objWMIService.ExecQuery("Select * from SMS_CM_RES_COLL_SMS00001 Where Name = '" & strComputer & "'")
If Err.Number <> 0 Then
objExcel.Cells(intRow, 1).Value = UCase(strComputer)
objExcel.Cells(intRow, 2).Value = "Not Found"
Err.Clear
End If
For Each objItem in colItems
objExcel.Cells(intRow, 1).Value = objItem.Name
objExcel.Cells(intRow, 2).Value = objItem.ResourceID
objExcel.Cells(intRow, 3).Value = objItem.SiteCode
objExcel.Cells(intRow, 4).Value = objItem.Domain
Next
intRow = intRow + 1
Loop
objExcel.Range("A1:D1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
MsgBox "Done"
No Comments