Windows operating system runs many services in background and they all are managed through services.msc console. Few application issues can be fixed by restarting their respective service.
We can restart service of single computer by manually logging in to the computer using remote desktop connection, whereas if you experience issues with multiple computers then logging-in to each and every computer manually through remote desktop will consume more time.
To resolve this issue we use powershell scripts, using the powershell script we can restart windows service for bulk computers all at once and it saves huge amount of manual effort and time.
Powershell script to restart service on multiple computers:
We use get-content to get the list of computers and assigned it to the variable $Computers.
ForEach($Computer in $Computers) { <#Our Code Here#> }
We use Get- Service followed by service name to find and fetch the service and passed the output to restart-service cmdlet using pipeline operator to restart the service. we used this script to restart BITS service on multiple computers
ForEach($Computer in $Computers) { Write-Verbose "Checking Computer $Computer" Write-Verbose "Restarting BITS Service on $Computer" Get-Service -Name 'BITS' -ComputerName $Computer | Restart-Service -PassThru Write-Host "BITS Service has been restarted successfully on $Computer" }
Combine all the individual scripts that are listed to a single script with simple function as mentioned below:
Function RestartService { $Computers = Get-Content (Read-Host 'Enter the computers list file path here') ForEach($Computer in $Computers) { Write-Verbose "Checking Computer $Computer" Write-Verbose "Restarting BITS Service on $Computer" Get-Service -Name 'BITS' -ComputerName $Computer | Restart-Service -PassThru Write-Host "BITS Service has been restarted successfully on $Computer" } } RestartService
Copy the script to the notepad file and save it with .ps1 extension and call the script from command prompt to execute.
Hope this article helps to solves your query on how to restart service on multiple computers. execute this script at your own risk and always try to execute the script in test environment before implementing in production as we do not provide any guarantee or warranty.