Skip to main content

Command referenceWhere-Object

Where-Object command (Windows / PowerShell)

WindowsPowerShelltextintermediate

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 / optionMeaning
-FilterScriptEvaluate a script block for each input object.
-PropertyChoose a property for comparison syntax.
-EQKeep objects whose property equals a value.
-MatchKeep objects matching a regular expression.
-NotNegate 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.

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.