I have a list of 10-15 services that I usually need to restart on 6 servers. I have a script that calls a list of services, then calls a list of servers, and then stops all services:
$Services = Get-Content -Path "C:\Powershell\Services.txt" $Machines = Get-Content -Path "C:\Powershell\Machines.txt" Get-Service -Name $Services -ComputerName $Machines | Set-Service -Status Stopped
Then I have another separate script to run them again:
$Services = Get-Content -Path "C:\Powershell\Services.txt" $Machines = Get-Content -Path "C:\Powershell\Machines.txt" Get-Service -Name $Services -ComputerName $Machines | Set-Service -Status Running
I checked and cannot find a way to put it in one script. As I understand it, Set-Service has the ability to stop, start, and pause services, rather than restarting them at the same time.
Any ideas? I might have missed something completely obvious.
Pjc83 source share