Announcement

Collapse
No announcement yet.

Help in fixing the complier error in Script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help in fixing the complier error in Script

    Hi All,
    I am new to Scripting please help me in fixing the issue
    This script is to check multiple servers service (startup type automatic) status check and if the service is not running report to log file.

    Below is the script.
    {Mod edit: added Code tags}
    Code:
     
    'The list of source servers against which the script is run against, is stored in a textfile named "servers.txt". 
     
    Set fso = createObject("Scripting.FileSystemObject") 
    Set outfile = fso.CreateTextFile("updates.txt")
    set Servicestate = fso.CreateTextFile("service.txt")
    src = "servers.txt"
    target = " "
     
    scriptstart = now
     
    'Open the source file for reading
    Set ts = fso.OpenTextFile(src,1)
    On Error resume next
    Do Until ts.AtEndOfStream
       'Read operation on the file; store the string value in each line, to a variable named strComputer for each execution of a do-while loop.
       strComputer = ts.ReadLine 
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
       Set colAutoStSvc = objWMIService.ExecQuery("SELECT * FROM Win32_Service " _
         & "WHERE StartMode = 'Auto'")
       For Each objService in colAutoStSvc
         If NOT objService.State = "Running" Then
           servicestate.writeline strComputer & ": The " & objService.DisplayName & " is in the " & _
             objService.State & " state."
         End If
      End
    Last edited by Rems; 22nd April 2010, 17:35.

  • #2
    Re: Help in fixing the complier error in Script

    Originally posted by Tech_MU View Post

    For Each objService in colAutoStSvc
    If NOT objService.State = "Running" Then
    servicestate.writeline strComputer & ": The " & objService.DisplayName & " is in the " & _
    objService.State & " state."
    End If
    End
    The "End" after End If should be Next, as it closes the For Each block.

    You also are missing Loop keyword at the end of the script.

    Please copy and paste the exact error message you get. It helps debugging.

    -vP

    Comment

    Working...
    X