Script to find state of service on remote computers
Posted: 11 May 2009 14:58
Can you help me write a script that will tell me if the "Windows Update" service on a several remote computers (list of IP addresses in notepad)
A Forum all about DOS Batch
https://www.dostips.com/forum/
Code: Select all
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSrcFile = objFSO.OpenTextFile("IPlist.txt",1,True)
Do Until objSrcFile.AtEndOfStream
strComputer = objSrcFile.ReadLine
If strComputer <> "" Then
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery ("Select * from Win32_Service Where DisplayName = 'Windows Update'")
For Each objService in colRunningServices
If objService.State <> "Running" Then
Wscript.Echo "The service is not running"
else
Wscript.Echo "The service is running"
End If
Next
End If
Loop