Eswar Koneti's Blog

All about Configmgr and its connected objects…….

  • About Author
      View eswar koneti's LinkedIn profile
  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 95 other subscribers

  • Awards


  • FaceBook Updates

  • Catagories

  • Meta

  • Copyright!

    All the blog posts in this website are owned by Eswar Koneti and may not be reused in any mode without prior approval of Eswar Koneti. You may quote one paragraph from the blog posts if you link to the original blog post.
    Happy Reading!

VBScript check the SMS agent host service status

Posted by Eswar Koneti on July 10th, 2012

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

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>