How to restart a service in Windows PowerShell

Have you ever felt the need to restart any of the windows service and its dependent services? There might be situation where you have to periodically restart the windows service due to various reasons.

One reason I have come across to restart windows service at specific period was when one of our domain controller's lsass process kept on utilizing memory and gradually increased the memory that ultimately resulted into a hung server.

We needed to find the root cause of the issue but until then we also needed to keep the services provided by domain controller up and running. As a temporary solution, we created the script to restart active directory services and it's dependent services which we configured to run at specific interval using task scheduler.

The script along with restarting the main service and it's dependent services, also checks whether any of the service has went into hang state. If any of the service is found to be in hang state, it will fetch the PID of the hang service and will kill the corresponding process. It will then attempt to restart the service once again.

The same script can be used to restart any other windows service as well. You just need to provide the name of the main service. Script will automatically get the dependent services.

The name of the main service should be mentioned in place of "ntds". Below lines of code will get the service name and it's dependent services.


#Get the ADDS and its dependent services
$set1 = @((Get-Service -Name ntds).Name)
$set2 = Get-Service -Name ntds -dependent | foreach {$_.name}
$set3 = $set1 + $set2


Below mentioned code will initiate the command to restart the services. It will store the result in apowershell job. Later you can check the status of the job. The script will then wait for 120 seconds to restart the services.


#Restart the ADDS and its dependent services
$job = start-job -scriptblock {Restart-Service -name ntds -force}

#Give time to restart the services
start-sleep -Seconds 120


Below mentioned code will check for the state of each service and if any of the service went in hung mode will restarting, it will kill the corresponding process and will reinitiate the restart of the service.

In this post, we will be discussing the topic of how to Enable or Disable Services and how to Start, Stop, and Restart Services in Windows 11 or Windows 10 using PowerShell, Command Prompt, Task Manager and Net Command.

How to restart a service in Windows PowerShell

Windows Services are applications that typically start when the computer is booted and run quietly in the background until it is shut down. Essentially, a service is any Windows application that is implemented with the services API and handles low-level tasks that require little or no user interaction.

Enable or Disable Services using PowerShell and Command Prompt in Windows

The Windows OS when installed and running on your device actually does a great job of automatically managing services, but sometimes you may need to manually enable or disable a service on demand. Keep in mind that if you disable a service, any dependent services are also affected; and enabling a service does not automatically restart its dependent services.

How do I Start a service in PowerShell?

To start or stop a service through PowerShell, you can use the Start-Service or the Stop Service cmdlet, followed by the name of the service that you want to start or stop. For instance, you might enter Stop-Service DHCP or Start-Service DHCP.

How do I restart a service remotely in PowerShell?

Method 3: Using PowerShell.
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..

How do I Start and stop a service in PowerShell?

Open Start. Search for PowerShell, right-click the top result, and select the Run as administrator option. Type the following command to disable a service and press Enter: Set-Service -Name "SERVICE-NAME" -Status stopped -StartupType disabled.

How to restart a service in Windows command line?

Use a command prompt.
To start a service, type: net start ServiceName..
To stop a service, type: net stop ServiceName..
To pause a service, type: net pause ServiceName..
To resume a service, type: net continue ServiceName..