How to Restart a Windows Service Using PowerShell?

In this tutorial, I will explain how to restart a Windows service using PowerShell. As a system administrator for a company, I recently had an issue where I needed to restart a critical service on one of our servers located in New York.

PowerShell Restart-Service Cmdlet

PowerShell provides a built-in cmdlet called Restart-Service that allows you to restart a Windows service. The Restart-Service cmdlet sends a stop message and then a start message to the Windows Service Controller for a specified service. This cmdlet can be used to restart services on both local and remote computers.

Restart a Service on the Local Computer using PowerShell

To restart a service on the local computer, follow these steps:

  1. Open PowerShell as an administrator.
  2. Use the Get-Service cmdlet to retrieve the service you want to restart. For example, if you want to restart the “Print Spooler” service, run the following command:
   Get-Service -Name 'Spooler'

This command will display information about the “Print Spooler” service, including its current status.

  1. To restart the service, use the Restart-Service cmdlet followed by the service name:
   Restart-Service -Name 'Spooler'

PowerShell will attempt to stop and then start the “Print Spooler” service.

  1. Verify that the service has been successfully restarted by running Get-Service again:
   Get-Service -Name 'Spooler'

The output should show that the service is now running.

Check out Install Git on Windows Using PowerShell

Restart a Service on a Remote Computer using PowerShell

To restart a service on a remote computer, you need to use the -ComputerName parameter with the Restart-Service cmdlet. Here’s an example:

  1. Open PowerShell as an administrator.
  2. To restart a service on a remote computer, use the following command:
   Restart-Service -Name 'Spooler' -ComputerName 'NYC-PrintServer01'

Replace 'Spooler' with the name of the service you want to restart and 'NYC-PrintServer01' with the name or IP address of the remote computer.

  1. PowerShell will attempt to connect to the remote computer, stop the specified service, and then start it again.
  2. To verify that the service has been successfully restarted on the remote computer, use the following command:
   Get-Service -Name 'Spooler' -ComputerName 'NYC-PrintServer01'

The output should confirm that the service is now running on the remote computer.

Check out Monitor and Manage CPU Usage using Windows PowerShell

Restart Multiple Services using PowerShell

If you need to restart multiple services at once, you can use the Get-Service cmdlet with the -DisplayName parameter to retrieve services based on a partial name match. Here’s an example:

  1. Open PowerShell as an administrator.
  2. To restart all services that contain the word “SQL” in their display name, use the following command:
   Get-Service -DisplayName '*SQL*' | Restart-Service

This command retrieves all services with “SQL” in their display name and pipes them to the Restart-Service cmdlet, which restarts each service one by one.

  1. To verify that the services have been successfully restarted, use the following command:
   Get-Service -DisplayName '*SQL*'

The output should show that all the matching services are now running.

Check out Disable Windows Defender Using PowerShell

Handle Services That Cannot Be Restarted

In some cases, you may encounter services that cannot be restarted due to dependencies or other issues. To handle such scenarios, you can use the -Force parameter with the Restart-Service cmdlet. The -Force parameter attempts to stop the service and all its dependent services before restarting them. Here’s an example:

  1. Open PowerShell as an administrator.
  2. To forcefully restart a service named “Windows Search” and its dependencies, use the following command:
   Restart-Service -Name 'WSearch' -Force

This command will attempt to stop the “Windows Search” service and its dependent services, and then start them again.

  1. Verify that the service and its dependencies have been successfully restarted by running:
   Get-Service -Name 'WSearch'

The output should indicate that the service is now running.

Conclusion

In this tutorial, I explained how to restart Windows services using PowerShell using the Restart-Service cmdlet. I explained how to restart a service on a local computer or a remote computer using PowerShell. I have also explained how to restart multiple services using PowerShell.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.