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
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
- Get-Sevice
- Stop-Service
- Start-Service
- Where-Object
- Restart-Service
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 Line
- How to List only Running or Stopped Services in PowerShell
- How to List a Service or Get Service by Name in Windows
- How to Search for the Service[s] by More Filters
- How to Stop the Service[s] in Windows Command Line
- How to Start the Service[s] in Windows Command Line
- How to Restart the Service[s] in Windows Command Line
Index
- How to List the Services Windows Command Line
- How to List only Running or Stopped Services in PowerShell
- How to List a Service or Get Service by Name in Windows
- How to Search for the Service[s] by Status, DisplayName, Search String etc.
- How to Stop the Service[s] in Windows Command Line
- How to Start the Service[s] in Windows Command Line
- How to Restart the Service[s] in Windows Command Line
How to List the Services in Windows Command Line
To List, all the Services in your Windows PC or Server, Perform the Following Steps
- Open PowerShell Terminal or PowerShell ISE as Administrator
- Type
Get-Service | Where-Object {$_.Status -eq "Running" }
1 in the Terminal
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 PowerShell
In 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
- Open PowerShell Terminal or PowerShell ISE as Administrator
- Use one of the following command based on your requirement
To List Only The Running Services
Get-Service | Where-Object {$_.Status -eq "Running" }
To List only the Stopped Services
Get-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 Windows
To 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
- Open PowerShell Terminal or PowerShell ISE as Administrator
- Use the following
Get-Service | Where-Object {$_.Status -eq "Running" }
1 the command along with aGet-Service | Where-Object {$_.Status -eq "Stopped" }
1 [or]Get-Service | Where-Object {$_.Status -eq "Stopped" }
2 parameter
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 Filters
Sometimes, 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 Line
We 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
- How to Stop a Single Service by Name
- How to Stop One or More Services matching the Query [or] Search term
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 Line
Now 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 Line
We 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
- Open PowerShell Terminal or PowerShell ISE as Administrator
- Use the following
Get-Service | Where-Object {$_.Status -eq "Running" }
1 the command along with aGet-Service | Where-Object {$_.Status -eq "Stopped" }
1 [or]Get-Service | Where-Object {$_.Status -eq "Stopped" }
2 parameter and List the Services you want to be restarted - In the same Command add a
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
6 symbol at the suffix along with a commandGet-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
7
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
Sarav AK
Follow us onFacebook orTwitter
For more practical videos and tutorials. Subscribe to our channel
Follow me on Linkedin My Profile
For any Consultation or to hire us [email protected]
If you like this article. Show your Support! Buy me a Coffee.
Signup for Exclusive "Subscriber-only" Content
Name*
Email*
More from Middleware Inventory
Netstat command windows - Usage and Examples
Introduction Like Linux, Windows does have a netstat command and it can come handy when you are in need of network-related monitoring and troubleshooting. Consider you have any of the following requirement How to find who or which process owns the port in Windows Server To see how many HTTP/DB…
How to Start Weblogic Admin and Managed Server in Command Line
The Objective In this post, we are going to see how to Start the Weblogic Admin and managed server in the command line. Presumably, most of the weblogic servers in the industry is running in LINUX Operating System and So this article is designed for the Linux as well. Prerequisite…
vagrant up command stuck at checking if box is up to date - How to solve
The Objective How to solve the situation where the vagrant up command gets stuck while checking if box is up to date . By default when you bring up the virtual machine provisioned with vagrant using vagrant up command.vagrant will look for the updates associated with the box and make…
Ansible Command Module Examples
Ansible Command Module Introduction Ansible Command module is used to execute commands on a remote node. The Command module, is used mostly to run simple Linux commands on a remote node/server which is part of a host group or Stand alone server mentioned in the host group. If you want…
Powershell Find String in file - How to use windows find command
If you are here, Then you might have had a similar requirement I had, which is to find a specific file across multiple directories and to grep or Search for a string present in that file. [ more like what we do with xargs in Linux] I am a Linux…
How do I restart Windows service?
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..How do I force a service to start manually?
Start service To start a service with the command line, use these steps: Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to start a service and press Enter: n et start "SERVICE-NAME"How do I force start a service in Windows 10?
You can launch services by opening Start, typing: services then hitting Enter. Or, you can press Windows key + R, type: services. msc then hit Enter. Services feature a very basic interface, but within it are hundreds of services, most bundled with Windows 10 and others added by third parties.How do you force a stuck Service to stop?
Click the Start menu..Click Run or in the search bar type services.msc..Press Enter..Look for the service and check the Properties and identify its service name..Once found, open a command prompt. Type sc queryex [servicename]..Press Enter..Identify the PID..In the same command prompt type taskkill /pid [pid number] /f..