Windows Services in Powershell

List Windows Services

To get a list of services, run the following command:

Get-Service

Here’s a list of my first 10 services:

PS K:\powershell> Get-Service | Select-Object -First 10
Status Name DisplayName
 ------ ---- -----------
 Running AdobeARMservice Adobe Acrobat Update Service
 Stopped AdobeFlashPlaye... Adobe Flash Player Update Service
 Stopped AeLookupSvc Application Experience
 Stopped ALG Application Layer Gateway Service
 Stopped ANTS Memory Pro... ANTS Memory Profiler 7 Service
 Stopped ANTS Performanc... ANTS Performance Profiler 7 Service
 Running AppHostSvc Application Host Helper Service
 Stopped AppIDSvc Application Identity
 Stopped Appinfo Application Information
 Stopped AppMgmt Application Management

Getting a list of services from a remote machine:

Invoke-Command -ComputerName <computername> -ScriptBlock { Get-Service }

Filtering Services

You have a few options when trying to filter the list of services. You can use Get-Service arguments or send the output to be filtered – note we’re filtering the service Name, not the service DisplayName:

PS K:\powershell> Get-Service *wsear*
Status Name DisplayName 
------ ---- ----------- 
Running WSearch Windows Search

To filter on display name with wildcards, specify the -DisplayName argument explicitly:

PS K:\powershell> Get-Service -DisplayName *Search*
Status Name DisplayName 
------ ---- ----------- 
Running WSearch Windows Search

Each service is a powershell object, so you can always pipe the content to a filter. Below we’re looking for any items that have the Name of Dhcp or WinRM. Note we’re using the Where-Object and evaluating the Name against a Regex collection by using -match command.

PS K:\powershell> Get-Service | Where-Object { $_.DisplayName -match "live|error" }
Status Name DisplayName 
------ ---- ----------- 
Stopped WerSvc Windows Error Reporting Service 
Running wlidsvc Windows Live ID Sign-in Assistant

Starting and Stopping Services

To start or stop a service use the Start-Service and Stop-Service cmdlets.

Find the Services you wish to start. Use the filtering to find a single instance. If there are multiple services and you pipe them to Start-Service or Stop-Service, they’ll all be started or stopped. If an error occurs for one service (e.g. it cannot start), the error will be reported to the console, but the rest of the services will be sent and attempted to be started.

Finding all services with *web* in the name:

PS C:\WINDOWS\system32> Get-Service *web*
Status Name DisplayName
------ ---- -----------
Running WebClient WebClient

Piping the services to Stop-Service:

PS C:\WINDOWS\system32> Get-Service *web* | Stop-Service

Chaining up more filtering and passing the services though the pipeline to Start-Service:

PS K:\powershell> Get-Service | Where-Object { $_.DisplayName -match "live|error" } | Start-Service