Command referenceWhere-Object
Where-Object command (Windows / PowerShell)
What it does
Filter pipeline objects by property values or a script block predicate. Guides covering the where-object powershell usually need pipeline-friendly examples, common parameters, and how the cmdlet compares with classic CMD or Linux tools. This page includes syntax, options, and copyable PowerShell examples.
Filter pipeline objects by property values or a script block predicate.
Syntax
Where-Object [-Property] <String> [[-Value] <Object>] -EQ | Where-Object -FilterScript <ScriptBlock>
Common options
| Flag / option | Meaning |
|---|---|
| -FilterScript | Evaluate a script block for each input object. |
| -Property | Choose a property for comparison syntax. |
| -EQ | Keep objects whose property equals a value. |
| -Match | Keep objects matching a regular expression. |
| -Not | Negate a property truth test. |
Practical examples
Running services
Get-Service | Where-Object Status -eq 'Running'
Keeps service objects with Running status.
Large files
Get-ChildItem -File | Where-Object Length -gt 10MB
Keeps files larger than ten MiB.
Name pattern
Get-Process | Where-Object { $_.Name -match '^code' }Uses a script predicate on process names.
Common mistakes
- Filtering formatted text instead of object properties.
- Using `=` assignment inside a script block when `-eq` comparison was intended.
Related commands
- ForEach-ObjectRun a script block for each object arriving through the pipeline.
- Select-StringSearch strings and files with .NET regular expressions.
- Get-ProcessRetrieve local or remote process objects and resource metrics.
- grepSearch text for lines matching a pattern.
- catConcatenate files and write their contents to standard output.
- Get-ContentRead file content or provider data as a stream of objects.
- echoWrite arguments and shell-expanded values to standard output.
- echoDisplay text or control command echoing in a batch script.
FAQ
What does Where-Object do in PowerShell?
Filter pipeline objects by property values or a script block predicate.
How can I see examples for Where-Object?
Run `Get-Help Where-Object -Examples`, then adapt an example to the provider and objects you are using.
What is a practical Where-Object example?
Try `Get-Service | Where-Object Status -eq 'Running'` — Keeps service objects with Running status.
Does Where-Object return text or objects?
Where-Object normally participates in PowerShell's object pipeline; formatting seen in the console is a view of those objects.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.