I threw a quick PowerShell function together that would allow me to restart one service on 1 or more servers in one command. I hadn’t found an easy way to do this in PowerShell before so I threw this together. What I did was pasted the function code into my PowerShell profile at c:\users\%USERNAME%\Documents\WindowsPowershell\Microsoft.PowerShell_profiles.ps1 to ensure it was loaded each time I started my PowerShell window. The syntax of the script is simple:
The service name is a simple string, and should be the short name of the service. The ServerNames option should be a comma separated list of servers that you want to restart the service on. It can be any number of servers, meaning you can use this to remotely stop the service on just 1 servers or 100. The output of the service being restarted looks like this:
Copy the below script:
Into your PowerShell profile at the below path. If the PS1 file isn’t there, you can manually create it:
Save and close the file and you should be ready to rock!
Disclaimer: This script is provided as is and I take no responsibility for any issue it causes in your environment. Please test in a lab before deploying to production.