Finding All Stoppable Services

by Feb 16, 2015

PowerShell 3.0 and later

Get-Service lists all services installed on your computer. It has no parameter to select only running or stopped services, though.

With a simple Where-Object clause, you can make up for this. Most often, you will see something like this:

PS> Get-Service | Where-Object Status -eq Running 

Basically, Where-Object takes any of the available object properties and lets you define a condition that needs to be met.

If you planned to get a list of stoppable services, the above line would not work well. Some services may be running but cannot be stopped. By adjusting your filter slightly, you still get what you need. This produces a list of running services that are actually stoppable:

PS> Get-Service | Where-Object CanStop 

And it simplifies the line, too: Since the property “CanStop” is already a Boolean value (true or false), there is no need for a comparison operator anymore.

To find the opposite and list all services that cannot be stopped, use a comparison operator:

PS> Get-Service | Where-Object CanStop -eq $false

Note that with the simplified syntax of Where-Object, you cannot reverse the result. The following lines will not work:

PS> Get-Service | Where-Object !CanStop 

PS> Get-Service | Where-Object -not CanStop 

To use these, or combine comparisons, use the full syntax:

PS> Get-Service | Where-Object { !$_.CanStop -and $_.Status -eq 'Running' }

Twitter This Tip! ReTweet this Tip!