Restart a service on multiple devices using Powershell

powershell
powershell

Estimated reading time: 2 minutes

We recently had a requirement to restart a single service on multiple devices across a single network. At first, it was going to be the job of the helpdesk to logon to each device and manually restart this service. However, as usual, there is always a way of using Powershell to speed up such tasks.

Powershell Script

This simple Powershell script will allow you to create a txt file with the list of device names in it and then run the below Powershell script as an administrator:

Get-Content C:TGHserverlist.txt | ForEach-Object { Restart-Service -InputObject $(Get-Service -Computer $_ -Name Spooler) }

Variables

The variables you will be most interested in changing are:

  • C:TGHserverlist.txt – this is the file location and filename of the text file that you have created with all the device names in where you want to restart the service. You can manually fill this in or use an Active Directory export or gather it from Configuration Manager data. The only information in there is the NETBIOS name of each device.
  • Spooler – this is the name of the service that you wish to restart. For this guides purpose we have used the Print Spooler – with the service name being Spooler:
Spooler Service

Remember not to use the Display Name of Print Spooler.

Then go ahead and run the Powershell script and it will go through your full list of devices from the txt file that you created and restart the single service on each of the devices.

Feedback

If you have any questions or feedback on this guide, then please feel free to leave us a message below in our comments section. Don’t forget that you can also download this guide as a free PDF eBook.

Click to rate this post!
[Total: 0 Average: 0]

Share this content:

Avatar for Andrew Armstrong

About Andrew Armstrong

Founder of TechyGeeksHome and Head Editor for over 15 years! IT expert in multiple areas for over 26 years. Sharing experience and knowledge whenever possible! Making IT Happen.

View all posts by Andrew Armstrong

Leave a Reply

Your email address will not be published. Required fields are marked *