VBS Script To Retrieve SMS Executive Service Information From A List Of Machines

 

This VBS script will read a text file called MachineList.Txt and will write the SMS Executive services information for the site servers to an excel spreadsheet. If the service state is stopped the results will be written in red.

 

VBS Script:

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

Set Fso = CreateObject("Scripting.FileSystemObject")

Set InputFile = fso.OpenTextFile("MachineList.Txt")

Do While Not (InputFile.atEndOfStream)

strComputer = InputFile.ReadLine

 

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

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

objExcel.Cells(1, 3).Value = "Current State"

 

servicename = "SMS_Executive"

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

Set colItems = objWMIService.ExecQuery("Select * From Win32_Service Where Name = '" & servicename & "'")

 

For Each objItem in colItems

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

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

objExcel.Cells(intRow, 3).Value = objItem.State

If objExcel.Cells(intRow, 3).Value = "Stopped" Then

objExcel.Cells(intRow, 3).Font.ColorIndex = 3

End If

 

intRow = intRow + 1

Next

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, August 24, 2008 1:07 PM by dhite
Filed under:

Comments

No Comments