Disable services on list of servers


Below script will be useful for disabling the services

'create a file called list.Txt
Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("list.Txt")
Do While Not (InputFile.atEndOfStream)
sComputer = InputFile.ReadLine
aTargetSvcs= Array("WDSServer")
'For list of services use below...
'arrTargetSvcs = Array("service1", "service2", "service3")


Set oWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!\\" _
 & sComputer & "\root\cimv2")
Set cServices = oWMIService.ExecQuery("SELECT * FROM Win32_Service")

For Each oService In cServices
 For Each sTargetSvc In aTargetSvcs
  If LCase(oService.Name) = LCase(sTargetSvc) Then
  
   If oService.State <> "Stopped" Then
    oService.StopService()   
   End If

   If oService.StartMode <> "Disabled" Then   
    oService.ChangeStartMode("Disabled")
   End If 

  End If 
 Next
Next
loop
MsgBox "Done"


 

0 comments:

Post a Comment