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:
- Open PowerShell as an administrator.
- Use the
Get-Servicecmdlet 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.
- To restart the service, use the
Restart-Servicecmdlet followed by the service name:
Restart-Service -Name 'Spooler'PowerShell will attempt to stop and then start the “Print Spooler” service.
- Verify that the service has been successfully restarted by running
Get-Serviceagain:
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:
- Open PowerShell as an administrator.
- 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.
- PowerShell will attempt to connect to the remote computer, stop the specified service, and then start it again.
- 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:
- Open PowerShell as an administrator.
- To restart all services that contain the word “SQL” in their display name, use the following command:
Get-Service -DisplayName '*SQL*' | Restart-ServiceThis 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.
- 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:
- Open PowerShell as an administrator.
- To forcefully restart a service named “Windows Search” and its dependencies, use the following command:
Restart-Service -Name 'WSearch' -ForceThis command will attempt to stop the “Windows Search” service and its dependent services, and then start them again.
- 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:
- Install Snipping Tool in Windows 11 Using PowerShell
- Get an IP Address Using PowerShell in Windows
- Set Service to Automatic Using PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.