How do I force restart a Windows service?
Windows Service management through the command line is really a good approach when you want to manage plenty of services and perform day to day actions like stop, start and restart Show
I think you would agree, If I say Status Name DisplayName ------ ---- ----------- Stopped AarSvc_ba23f Agent Activation Runtime_ba23f Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Stopped AppIDSvc Application Identity Running Appinfo Application Information Stopped AppReadiness App Readiness Running AppXSvc AppX Deployment Service (AppXSVC) Running AudioEndpointBu... Windows Audio Endpoint Builder Running Audiosrv Windows Audio Stopped autotimesvc Cellular Time Stopped AxInstSV ActiveX Installer (AxInstSV) Stopped BcastDVRUserSer... GameDVR and Broadcast User Service_... Stopped BDESVC BitLocker Drive Encryption Service8 is fun for entry-level but when it comes to performing the job smartly and creating automation for efficiency. Status Name DisplayName ------ ---- ----------- Stopped AarSvc_ba23f Agent Activation Runtime_ba23f Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Stopped AppIDSvc Application Identity Running Appinfo Application Information Stopped AppReadiness App Readiness Running AppXSvc AppX Deployment Service (AppXSVC) Running AudioEndpointBu... Windows Audio Endpoint Builder Running Audiosrv Windows Audio Stopped autotimesvc Cellular Time Stopped AxInstSV ActiveX Installer (AxInstSV) Stopped BcastDVRUserSer... GameDVR and Broadcast User Service_... Stopped BDESVC BitLocker Drive Encryption Service9 is your key Get-Service | Where-Object {$_.Status -eq "Running" }0has a lot of commands to help us manage the windows server better and create automation and do the boring (or) repetitive tasks swiftly In this article, we are going to see How to Manage Services from the Windows Command line using PowerShell. We are going to see various examples of How to List , Stop, Start, Restart a Single Service or multiple Services. To Manage the Services in Windows, We have a pack of Powershell commands and each does a unique job in the Windows Service Management. It helps us perform our day to day needs like Stopping, Starting, Restarting, Listing, Searching, etc In this article, we are going to see various Windows Powershell commands such as
Not just this, There are few more and look at the index to know what this article is packaged with I am thrilled and I hope you are too. Let’s march on.
Table of Contents
Index
How to List the Services in Windows Command LineTo List, all the Services in your Windows PC or Server, Perform the Following Steps
You would be presented with all the available Services on the Windows Machine The result would container three columns as shown below, Status, Name, and DisplayName You can search or List a Single or Multiple Services based on any of these columns, which we will see in upcoming sections on this article. PS C:\Users\sarav> Get–Service Status Name DisplayName ------ ---- ----------- Stopped AarSvc_ba23f Agent Activation Runtime_ba23f Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Stopped AppIDSvc Application Identity Running Appinfo Application Information Stopped AppReadiness App Readiness Running AppXSvc AppX Deployment Service (AppXSVC) Running AudioEndpointBu... Windows Audio Endpoint Builder Running Audiosrv Windows Audio Stopped autotimesvc Cellular Time Stopped AxInstSV ActiveX Installer (AxInstSV) Stopped BcastDVRUserSer... GameDVR and Broadcast User Service_... Stopped BDESVC BitLocker Drive Encryption Service
How to List only Running or Stopped Services in PowerShellIn this section we are going to see how to list the windows services based on a Specific State they are in. To List, Either only Running and Stopped Services, PowerShell Get-Service | Where-Object {$_.Status -eq "Running" }1 Command can be used along with one more Filtering command named Get-Service | Where-Object {$_.Status -eq "Running" }3 . It acts like a Get-Service | Where-Object {$_.Status -eq "Running" }4 of Linux and it does the job so perfect and precise So to List Running or Stopped Services in Windows Command line you should do the following
To List Only The Running ServicesGet-Service | Where-Object {$_.Status -eq "Running" } To List only the Stopped ServicesGet-Service | Where-Object {$_.Status -eq "Stopped" } In fact, You can Use any of the Following Get-Service | Where-Object {$_.Status -eq "Running" }5 in place of Get-Service | Where-Object {$_.Status -eq "Running" }6 or Get-Service | Where-Object {$_.Status -eq "Running" }7 to get the Services in that State.ValueMeaningContinuePendingThe service has been paused and is about to continue.PausedThe service is paused.PausePendingThe service is in the process of pausing.RunningThe service is running.StartPendingThe service is in the process of starting.StoppedThe service is not running.StopPendingThe service is in the process of stopping. For example, If you would like to Get a Service which is in Get-Service | Where-Object {$_.Status -eq "Running" }8 State then your command should be like this Get-Service | Where-Object {$_.Status -eq "Paused" }
How to List a Service or Get Service by Name in WindowsTo List or to Get a Service by Name you have to be aware of the Name of the Service or at least a part of the Service name as we can use Get-Service | Where-Object {$_.Status -eq "Running" }9 wildcard to find the rest. To List or to Get Service by Name do the following
To List a Service named Get-Service | Where-Object {$_.Status -eq "Stopped" }3 I can use any of the following commands and Be informed that Service Name is Case Insensitive Get-Service -Name jenkins (or) Get-Service -Name jenkins (or) Get-Service -DisplayName jenkins (or) Get-Service -Name JEnKins (or) Get-Service -DisplayName JEnKins (or) Get-Service -Name jen*s
How to Search for the Service[s] by More FiltersSometimes, Our requirement would not be simpler as we think, It might get complicated when we get a requirement like We might have to list (or) restart all the tomcat instances running on the server and exclude instance which contains a Specific String in its name Let’s Suppose, that we have a Windows Server with N number of Tomcat Services (instances) and they are named after their Environment name they belong to like dev, uat etc. like Dev_Tomcat1, Test_Tomcat2, Uat_Tomcat4 and so on. Now to list only the Get-Service | Where-Object {$_.Status -eq "Stopped" }4 and Get-Service | Where-Object {$_.Status -eq "Stopped" }5 instances and not Get-Service | Where-Object {$_.Status -eq "Stopped" }6 we would have to use some more filters other than just Get-Service | Where-Object {$_.Status -eq "Stopped" }7 or Get-Service | Where-Object {$_.Status -eq "Stopped" }8 Here are some examples related to this type of scenario. # All these examples made based on the presence of # Environment Names `SIT` `UAT` `Dev` in the Service Name of # Service Display Name # The Search is By Default CASE INSENSITIVE # Find Tomcat Instances belong to Test Environment Get-Service -DisplayName "*Tomcat*" -Include "*Test*" (or) Get-Service -DisplayName "*Tomcat*" -Include "*tEst*" ---- # Find All Tomcat Instances EXCEPT the ones belong TEST Environment Get-Service -DisplayName "*Tomcat*" -Exclude "*Test*" -- – # You can also add STATUS Filter into this command Get-Service -DisplayName "*Tomcat*" -Exclude "*Test*"|Where-Object {$_.Status -eq "Running"}
How to Stop the Service[s] in Windows Command LineWe have so far seen, how to list the services in windows machine (PC or Server) using the Powershell command line. Now we are going to see, How to Stop the Service[s] in Windows PowerShell Command Line Now let us Split this Part into two as follows
Despite you are stopping a Single Service or Multiple Services. You have to first list the Services with Get-Service | Where-Object {$_.Status -eq "Running" }1 with necessary Filters like Get-Service | Where-Object {$_.Status -eq "Stopped" }1 or Get-Service | Where-Object {$_.Status -eq "Paused" }1 etc. Once the result is presented, With the help of Get-Service | Where-Object {$_.Status -eq "Paused" }2 Get-Service | Where-Object {$_.Status -eq "Paused" }3 symbol you pass all the services to an another Command called Get-Service | Where-Object {$_.Status -eq "Paused" }4 Get-Service | Where-Object {$_.Status -eq "Paused" }4 command is responsible to stop the service (or) Services Simply put, to Stop the Service or Services. You just need to list it first and make sure thats what you want to be stopped and then redirect it to Get-Service | Where-Object {$_.Status -eq "Paused" }4 with the help of pipe Here are some of Windows Stop Service Example commands # Simply Stop the Service named Jenkins Get-Service -Name Jenkins|Stop-Service --- # Stop all Running Services Get-Service|Where-Object {$_.Status -eq "Running"}|Stop-Service --- # List and Stop All Running *Tomcat* Services Get-Service -DisplayName "*Tomcat*"|Where-Object {$_.Status -eq "Running"}|Stop-Service --- # List and Stop All Running Tomcat Services, # Only Production, No DEV, UAT, SIT ( We Presume Display Name Contains the Environment Name) Get-Service -DisplayName "*Tomcat*" -Exclude "*DEV*" "*SIT*" "*UAT*"|Where-Object {$_.Status -eq "Running"}|Stop-Service
How to Start the Service[s] in Windows Command LineNow we are going to see, How to Start the Service[s] in Windows PowerShell Command Line Despite you are Starting a Single Service or Multiple Services. You have to first list the Services with Get-Service | Where-Object {$_.Status -eq "Running" }1 with necessary Filters like Get-Service | Where-Object {$_.Status -eq "Stopped" }1 or Get-Service | Where-Object {$_.Status -eq "Paused" }1 etc. Once the result is presented, With the help of Get-Service | Where-Object {$_.Status -eq "Paused" }2 Get-Service | Where-Object {$_.Status -eq "Paused" }3 symbol you pass all the services to another Command called Get-Service -Name jenkins (or) Get-Service -Name jenkins (or) Get-Service -DisplayName jenkins (or) Get-Service -Name JEnKins (or) Get-Service -DisplayName JEnKins (or) Get-Service -Name jen*s2 Here are some of Windows Start Service from Command Line examples # Simply Stop the Service named Jenkins Get-Servicec -Name Jenkins| Start-Service --- # Stop all Running Services Get-Service|Where-Object {$_.Status -eq "Running"}| Start-Service Status Name DisplayName ------ ---- ----------- Stopped AarSvc_ba23f Agent Activation Runtime_ba23f Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Stopped AppIDSvc Application Identity Running Appinfo Application Information Stopped AppReadiness App Readiness Running AppXSvc AppX Deployment Service (AppXSVC) Running AudioEndpointBu... Windows Audio Endpoint Builder Running Audiosrv Windows Audio Stopped autotimesvc Cellular Time Stopped AxInstSV ActiveX Installer (AxInstSV) Stopped BcastDVRUserSer... GameDVR and Broadcast User Service_... Stopped BDESVC BitLocker Drive Encryption Service0 Start-Service Status Name DisplayName ------ ---- ----------- Stopped AarSvc_ba23f Agent Activation Runtime_ba23f Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Stopped AppIDSvc Application Identity Running Appinfo Application Information Stopped AppReadiness App Readiness Running AppXSvc AppX Deployment Service (AppXSVC) Running AudioEndpointBu... Windows Audio Endpoint Builder Running Audiosrv Windows Audio Stopped autotimesvc Cellular Time Stopped AxInstSV ActiveX Installer (AxInstSV) Stopped BcastDVRUserSer... GameDVR and Broadcast User Service_... Stopped BDESVC BitLocker Drive Encryption Service1 Start-Service Status Name DisplayName ------ ---- ----------- Stopped AarSvc_ba23f Agent Activation Runtime_ba23f Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Stopped AppIDSvc Application Identity Running Appinfo Application Information Stopped AppReadiness App Readiness Running AppXSvc AppX Deployment Service (AppXSVC) Running AudioEndpointBu... Windows Audio Endpoint Builder Running Audiosrv Windows Audio Stopped autotimesvc Cellular Time Stopped AxInstSV ActiveX Installer (AxInstSV) Stopped BcastDVRUserSer... GameDVR and Broadcast User Service_... Stopped BDESVC BitLocker Drive Encryption Service2
How to Restart the Service[s] in Windows Command LineWe have just learned how to Stop and Start the services, Now it is a time to learn How to Restart Service from Windows Command Line To Restart windows Service Command Line do the following
To Restart Windows Service from Command Line, First we need to list the services that we want to be restarted using Get-Service | Where-Object {$_.Status -eq "Running" }1 we can customize and Search for the Services you want using Get-Service | Where-Object {$_.Status -eq "Running" }1 parameters like Get-Service | Where-Object {$_.Status -eq "Stopped" }7 and Get-Service | Where-Object {$_.Status -eq "Stopped" }8 , Get-Service | Where-Object {$_.Status -eq "Paused" }1 etc Once we have the list ready with Single or Multiple Services that we want to restart. We can use another command, Given dedicatedly to restart services named Get-Service -Name jenkins (or) Get-Service -Name jenkins (or) Get-Service -DisplayName jenkins (or) Get-Service -Name JEnKins (or) Get-Service -DisplayName JEnKins (or) Get-Service -Name jen*s7 In most cases, we would like to have more control on the Restart process, in such cases, you can try to # All these examples made based on the presence of # Environment Names `SIT` `UAT` `Dev` in the Service Name of # Service Display Name # The Search is By Default CASE INSENSITIVE # Find Tomcat Instances belong to Test Environment Get-Service -DisplayName "*Tomcat*" -Include "*Test*" (or) Get-Service -DisplayName "*Tomcat*" -Include "*tEst*" ---- # Find All Tomcat Instances EXCEPT the ones belong TEST Environment Get-Service -DisplayName "*Tomcat*" -Exclude "*Test*" -- – # You can also add STATUS Filter into this command Get-Service -DisplayName "*Tomcat*" -Exclude "*Test*"|Where-Object {$_.Status -eq "Running"}4 and # All these examples made based on the presence of # Environment Names `SIT` `UAT` `Dev` in the Service Name of # Service Display Name # The Search is By Default CASE INSENSITIVE # Find Tomcat Instances belong to Test Environment Get-Service -DisplayName "*Tomcat*" -Include "*Test*" (or) Get-Service -DisplayName "*Tomcat*" -Include "*tEst*" ---- # Find All Tomcat Instances EXCEPT the ones belong TEST Environment Get-Service -DisplayName "*Tomcat*" -Exclude "*Test*" -- – # You can also add STATUS Filter into this command Get-Service -DisplayName "*Tomcat*" -Exclude "*Test*"|Where-Object {$_.Status -eq "Running"}5 the services using Get-Service | Where-Object {$_.Status -eq "Paused" }4 and Get-Service -Name jenkins (or) Get-Service -Name jenkins (or) Get-Service -DisplayName jenkins (or) Get-Service -Name JEnKins (or) Get-Service -DisplayName JEnKins (or) Get-Service -Name jen*s2 commands rather directly using Get-Service -Name jenkins (or) Get-Service -Name jenkins (or) Get-Service -DisplayName jenkins (or) Get-Service -Name JEnKins (or) Get-Service -DisplayName JEnKins (or) Get-Service -Name jen*s7 Here are few examples of How to restart the Service in Windows Command Line # Simply Stop the Service named Jenkins Get-Servicec -Name Jenkins| Restart-Service --- # Stop all Running Services Get-Service|Where-Object {$_.Status -eq "Running"}| Restart-Service Status Name DisplayName ------ ---- ----------- Stopped AarSvc_ba23f Agent Activation Runtime_ba23f Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Stopped AppIDSvc Application Identity Running Appinfo Application Information Stopped AppReadiness App Readiness Running AppXSvc AppX Deployment Service (AppXSVC) Running AudioEndpointBu... Windows Audio Endpoint Builder Running Audiosrv Windows Audio Stopped autotimesvc Cellular Time Stopped AxInstSV ActiveX Installer (AxInstSV) Stopped BcastDVRUserSer... GameDVR and Broadcast User Service_... Stopped BDESVC BitLocker Drive Encryption Service0 Restart-Service Status Name DisplayName ------ ---- ----------- Stopped AarSvc_ba23f Agent Activation Runtime_ba23f Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Stopped AppIDSvc Application Identity Running Appinfo Application Information Stopped AppReadiness App Readiness Running AppXSvc AppX Deployment Service (AppXSVC) Running AudioEndpointBu... Windows Audio Endpoint Builder Running Audiosrv Windows Audio Stopped autotimesvc Cellular Time Stopped AxInstSV ActiveX Installer (AxInstSV) Stopped BcastDVRUserSer... GameDVR and Broadcast User Service_... Stopped BDESVC BitLocker Drive Encryption Service1 Restart-Service Status Name DisplayName ------ ---- ----------- Stopped AarSvc_ba23f Agent Activation Runtime_ba23f Stopped AJRouter AllJoyn Router Service Stopped ALG Application Layer Gateway Service Stopped AppIDSvc Application Identity Running Appinfo Application Information Stopped AppReadiness App Readiness Running AppXSvc AppX Deployment Service (AppXSVC) Running AudioEndpointBu... Windows Audio Endpoint Builder Running Audiosrv Windows Audio Stopped autotimesvc Cellular Time Stopped AxInstSV ActiveX Installer (AxInstSV) Stopped BcastDVRUserSer... GameDVR and Broadcast User Service_... Stopped BDESVC BitLocker Drive Encryption Service2
So This is how Windows PowerShell commands help us to manage the Windows services from Command line, We learned how to List, stop, start and restart windows services from command line With this command line, We can stop, start, restart Multiple services at once in bulk that’s what I like the most about it. If you have any questions for me. Please feel free to comment Rate this article [ratings] Share it with your friends if you find it worth Cheers Follow us onFacebook orTwitter Signup for Exclusive "Subscriber-only" Content Name* Email* More from Middleware Inventory
|