In powershell 3.0
$services = "service1", "service2", "service3"
"server1", "server2", "server3" | % {
Get-Service -Computer $_ $services | ? State -eq "Running" | Stop-Service -Force -PassThru | Set-Service -StartupType Disabled
}
You need to enable powreshell remoting for this to work and add -Credential
option anywhere you see -Computer
argument if your current domain user doesn't have enough rights.
More generic option would be to use hash
$ServiceMap = @{ "server1": ("service11", "service12");
"server2": ("service21" ... ) }
You will also need to check for errors..
To achieve parallel execution you could do something like:
workflow set_services {
param(
[string[]]$Computers, [string[]]$Services
)
foreach -parallel ($computer in $computers) {
Get-Service -ComputerName $computer $services | ? State -eq "Running" | Stop-Service -Force -PassThru | Set-Service -StartupType Disabled
}
}
BTW, do not use batch scripts any more, anywhere.