I was recently approached by one of my colleagues with a dilemma, he had to go round our 30+ servers and stop and start a couple of Sophos’s Windows Services.
Now, as you can imagine this was starting to look like a fairly large and mundane task. Which is when I came up with this little VBScript.
Using this script below, you can pass it a text file with a list of machines you would like it to perform the process on.
In the script below you will see a “” change this to your text file containing machines, full file path.
The format of the text file is one machine per line.
This script is by no means ‘bullet proof’ and could be enhanced easily with little time and effort. It could also be modfied to stopstart any services you like.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ ("", ForReading) Do Until objTextFile.AtEndOfStream strComputer = objTextFile.Readline Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2") Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name='Sophos Message Router'") For Each objService in colServiceList errReturn = objService.StopService() WScript.Echo errReturn Next Wscript.Sleep 20000 Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name='Sophos Message Router'") For Each objService in colServiceList errReturn = objService.StartService() WScript.Echo errReturn Next Loop |