hdxpdd
IS-IT--Management
- Jun 17, 2012
- 4
Hello
I'm relatively new to scripting and trying to find out if a service exists on a number of Servers but I'm stuck and can't figure out why the following code is not working
I would appreciate if to hear your comments.
Thanks
I'm relatively new to scripting and trying to find out if a service exists on a number of Servers but I'm stuck and can't figure out why the following code is not working
Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("c:\test\Servernames.txt", 1)
Do until oFile.AtEndOfStream
strNextLine = oFile.Readline
arrServer = split(strNextLine, ",")
Loop
oFile.Close
For Each strServer in arrServer
Set objWMIService = GetObject("winmgmts:" & "{ImpresonationLevel=impresonate}!\\" & strServer & "\root\cimv2")
Set sCol = objWMIServices.ExecQuery("SELECT * FROM Win32_Service where Name = 'W3SVC'")
if sCol.count = 0 then
Wscript.Echo = strServer & ", " & Now & ", " & "Service Does not Exists"
Else
Wscript.Echo = strServer & ", " & Now & ", " & "Service Exists"
End if
next
I would appreciate if to hear your comments.
Thanks