Restart remote services
Simple script to loop through multiple servers and services and restart the services. Just replace server and service names and run.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
## define your servers in an array
$Servers = "Server1","Server2","Server3"
## define your services in an array
$Services = "Service1","Service1","Service1"
## Loop through server array
foreach($Server in $Servers){
## Loop through service array
foreach($Service in $Services){
Write-Host "Restarting service $Service on $Server" -ForegroundColor Green
## Restart the service on the remote server
Invoke-Command -ComputerName $Server -ScriptBlock{
Restart-Service -Name $using:Service
}
}
}
This post is licensed under CC BY 4.0 by the author.