I have created a script to query services to retrieve their service account information. To begin, I execute the script locally and it does retrieve the correct information. However, I would like to modify the script to poll a list of services for their service account info and write the results to a csv file.
I have 3 issues I would like to address:
1. One issue I am having is how to properly setup the Do Loop. As it stands, the message I get is "loop without a do"
2. How to allow the script to proceed through an error with a host in the list. I believe I have the proper syntax, but I cannot verify without solving the loop issue.
3. How to modify the service polled to look for a wild card...For example, poll every service with the word "microsoft" in it.
I really appreciate the assistance.
Script below.
---------------------------
On Error Resume Next
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\service_list.csv", _
ForAppending, True)
Set objTextFile = objFSO.OpenTextFile("C:\list.txt",1)
objLogFile.Write _
("System Name,Service Name, Account Name ")
objLogFile.Writeline
strComputer = objTextFile.Readline
Do Until objTextFile.AtEndOfStream
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='Alerter'")
Set objLogFile = objFSO.OpenTextFile("c:\service_list.csv", _
ForAppending, True)
For Each objService in colListOfServices
objLogFile.Write(objService.SystemName) & ","
objLogFile.Write(objService.Name) & ","
objLogFile.Write(objService.StartName) & ","
Loop
objLogFile.Close
I have 3 issues I would like to address:
1. One issue I am having is how to properly setup the Do Loop. As it stands, the message I get is "loop without a do"
2. How to allow the script to proceed through an error with a host in the list. I believe I have the proper syntax, but I cannot verify without solving the loop issue.
3. How to modify the service polled to look for a wild card...For example, poll every service with the word "microsoft" in it.
I really appreciate the assistance.
Script below.
---------------------------
On Error Resume Next
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\service_list.csv", _
ForAppending, True)
Set objTextFile = objFSO.OpenTextFile("C:\list.txt",1)
objLogFile.Write _
("System Name,Service Name, Account Name ")
objLogFile.Writeline
strComputer = objTextFile.Readline
Do Until objTextFile.AtEndOfStream
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='Alerter'")
Set objLogFile = objFSO.OpenTextFile("c:\service_list.csv", _
ForAppending, True)
For Each objService in colListOfServices
objLogFile.Write(objService.SystemName) & ","
objLogFile.Write(objService.Name) & ","
objLogFile.Write(objService.StartName) & ","
Loop
objLogFile.Close