Get Current Management Point and Site Code From List Output To Excel

 

This VBS script will take the machine names from a text file called MachineList.Txt and write the machine(s) name, Current Management Point and site code to an excel spreadsheet.

 

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 = "Current Management Point"

objExcel.Cells(1, 3).Value = "Site Code"

 

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/ccm")

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

 

For Each objItem in colItems

strSiteCode = Replace(objItem.Name, "SMS:", "")

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

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

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

Next

 

intRow = intRow + 1

loop

 

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, July 29, 2007 2:08 PM by dhite
Filed under:

Comments

No Comments