Where-Object
Use Where-Object to select objects from a collection based on their property values. See Microsoft.PowerShell.Utility module requirements and examples.
Documentation: Microsoft Learn — Where-Object
Syntax
See the command anatomy
Inspect this authored example with fictional data in the bounded browser model. The numbered stages show how its objects change.
Get-Service | Where-Object Status -eq Stopped- Stage 1Get-Service
Positional values or no named parameters - Stage 2Where-Object
-eq
The object workshop
Watch your command work.
Change the command. Step through the pipeline. Inspect what survives.
Browser simulation · fictional services · Ctrl+Enter to run
Object properties
Enable JavaScript to step through this example. The lessons and command reference remain available.
Your task: return the stopped service, with exactly Name and Status.
Follow the objects
Run the command to inspect each stage.
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Filter by Status
Show reference output
Illustrative output · values vary by environment
Name Status StartType DisplayName ----- ------- --------- ------------------------- WinRM Stopped Manual Windows Remote Management
Filter by CPU
Show reference output
Illustrative output · values vary by environment
Name ProcessName Id CPU WS WorkingSet WorkingSet64 ------- ----------- ---- ------ --------- ---------- ------------ chrome chrome 9184 842.31 486539264 486539264 486539264 MsMpEng MsMpEng 2600 950 220200960 220200960 220200960
Filter by CPU and Id
Show reference output
Illustrative output · values vary by environment
Name ProcessName Id CPU WS ------- ----------- ---- ------ --------- chrome chrome 9184 842.31 486539264 MsMpEng MsMpEng 2600 950 220200960
Parameters
Parameter definitions:
-FilterScript-Property-Value-EQ
Practical use and troubleshooting
Practical scenario: Use Where-Object when you need to select objects from a collection based on their property values. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: An empty result may come from filtering a property that was already removed. Inspect Get-Member and apply the filter before a Select-Object projection that drops the required property. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Select-Object. Where-Object keeps matching input objects; Select-Object chooses properties or a subset of objects. Projection is different from testing whether an object satisfies a condition. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Put this command to work
Filter stopped services
Return the complete records for stopped services.
The sandbox is visible now. Sign in with Google only when you run or check a task; commands and temporary files are discarded when you leave.
Run a command to inspect its result.
Inspect starting data
Supported syntax
Virtual files
Recap
Where-Object Use Where-Object to select objects from a collection based on their property values. See Microsoft.PowerShell.Utility module requirements and examples.
Next: ForEach-Object