Stopping & Restarting Services Remotely Using Set-Service

前端 未结 3 2011
感动是毒
感动是毒 2021-01-12 01:19

I\'ve got a list of 10-15 services that I routinely need to restart on 6 servers. I have a script that calls a list of services, then calls a list of the servers, and then s

3条回答
  •  悲哀的现实
    2021-01-12 02:04

    You can try this single liner command:

    Get-Content .\services.txt | %{Get-WmiObject -Class Win32_Service -ComputerName (Get-Content .\computers.txt) -Filter "Name='$_'"} | %{$_.StopService()}; Get-Content .\services.txt | %{Get-WmiObject -Class Win32_Service -ComputerName (Get-Content .\computers.txt) -Filter "Name='$_'"} | %{$_.StartService()}
    

提交回复
热议问题