Restarting a service is quite a common task to any system administrators, whether on a local system or a remote computer. Now let’s take look a number of ways how to start, stop, and restart a service on a remote computer.
Table of Contents
How to get the name of a service
Before we dive into the ways to operate remote service, let’s check how to get the proper the name of the service first because it will be used by any command or PowerShell cmdlet listed below.
One thing worth pointing out is that the names listed in Name column in Services MMC are not the service name used in the command lines below. They are just the Display Name of the services. You will need to open the service properties dialog to find out.
It’s a built-in command line since Windows XP. It interacts with local and remote services quite easily like this:
SC \\computername STOP servicename
SC \\computername START servicename
You can put these commands in a batch file and run it as a login script or a scheduled task.
If you know the name of the service you want to interactive, SC is pretty to deal with. However, it doesn’t work well with those services that have dependent services to rely on.
One thing to note that SC doesn’t have the option to restart the service. So if you need to restart a remote service, you will need to do STOP and START separately.
By the way, you can use SC to get the name of the service, like below:
SC GetKeyName "service display name"
PSService from Sysinternals
If you are a fan of Windows Sysinternals, you can use PSService.exe that works similar to SC and does get the job done as well. It does include a switch that can restart the service.
psservice \\computername restart service
But it still doesn’t handle the service with the dependencies well.
There are multiple ways to deal with services using PowerShell. But the following scripts seem to be the easiest ways to me.
Get-Service -ComputerName computername -Name servicename | Restart-Service -Force
Get-Service -ComputerName computername -Name servicename | Stop-Service -Force
Get-Service -ComputerName computername -Name servicename | Start-Service
The -Force parameter here is to deal with the service with the dependencies.
Basically, the Get-Service cmdlet with -ComputerName returns an object reference to the service in the question. And then pipe the result to Start-Service, Stop-Service, or Restart-Service to perform the respective actions.
You can also throw in the Test-Connection cmdlet in the script to test the remote connection before querying the service.
Service Manager MMC
And of course, we can always use the built-in Service Manager MMC (services.msc) to perform the job as well. To connect to a remote services MMC, click the Services name in the left pane, go to Action, then Connect to another computer…
Once connected, you can operate the services just like you do on the local system.