VBScript check the SMS agent host service status

This script requires one notepad file(Input) with list of machines you need for and output(CSV Format) will be opened once the script runs.

Set fso=CreateObject("scripting.filesystemobject")
Set objinputfile=fso.OpenTextFile("eskonr.txt",1,True)
Set objoutputfile=fso.OpenTextFile("servicestatus.csv",2,True)
Do While objinputfile.AtEndOfLine <> True
strcomputer=objinputfile.ReadLine
Set objWMIService = GetObject("winmgmts:"_
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service WHERE DisplayName like 'SMS Agent Host'")
    objoutputfile.WriteLine("computer name:" & strcomputer)
    For Each objService in colRunningServices
        If Len(objservice.displayname) >= 40 Then
    objoutputfile.WriteLine(Left(objService.DisplayName,40)&vbTab & objService.State)
    Else
    objoutputfile.WriteLine(objService.DisplayName & Space(40-Len(objService.DisplayName))& vbtab& objService.State)
    'Wscript.Echo objService.DisplayName  & VbTab & objService.State
    End if
    Next
Loop

msgbox("Done")

Leave a Reply