where

PowerShell cmdlet to list services that are stopped

Get-Service * | Where-Object {$_.Status -eq "Stopped"}

The ‘Where’ command crops up in many PowerShell scripts, therefore it is worth familiarizing yourself with the rhythm of the command:

Begin the where clause with a pipe ‘|’. Next open {Braces (not parenthesis)}, pay close attention to $_. These three symbols translate to ’this pipeline’. In the above example, I have chosen to filter the services based on the value of the property ‘Status’.

Remember that PowerShell uses -eq and not the equals sign. Finally, we have the criterion: “Stopped”, an alternative filter would be, “Running”.

Challenge: Try changing “Stopped” to “Running”.

For your notebook: In other PowerShell scripts the structure of the ‘Where’ statement would be the same, however, you would replace .Status with a property to suit your purpose. Each property has its own values which you would research, then substitute for “Stopped”.

Last modified July 21, 2024: update (e2ae86c)