100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Filtering and Selecting

Master Where-Object for keeping only the rows you need and Select-Object for keeping only the properties you need, plus the operators that power both.

Pipeline & ObjectsBeginner10 min readJul 10, 2026
Analogies

Filtering with Where-Object

Where-Object narrows the pipeline down to only the objects that satisfy a condition, evaluating a script block against each incoming object referenced as $_. Objects for which the condition returns $true continue down the pipeline; everything else is discarded before it ever reaches the next cmdlet, which is exactly why filtering is normally placed as early as possible in a pipeline.

🏏

Cricket analogy: Where-Object is like a selector reviewing every player in the domestic circuit and keeping only those with a strike rate above 140, discarding the rest from consideration for the T20 squad.

powershell
Get-Service | Where-Object { $_.Status -eq 'Running' -and $_.StartType -eq 'Automatic' }

Comparison and Logical Operators

PowerShell's comparison operators are words, not symbols: -eq, -ne, -gt, -lt, -ge, and -le compare values, -like matches simple wildcards, and -match compares against a regular expression. Multiple conditions combine with -and, -or, and -not, letting a single Where-Object script block express fairly complex filtering logic in one readable line.

🏏

Cricket analogy: Choosing -eq versus -like is like a scorer deciding between an exact match on "century" versus a wildcard search for any score containing "50", each operator suited to a different kind of stat query.

Selecting Properties with Select-Object

Where Where-Object decides which rows of data survive, Select-Object -Property decides which columns survive, trimming an object down to only the named properties you care about, optionally adding calculated ones. Select-Object also supports -First, -Last, and -Unique to slice the object stream by count or de-duplicate it, which is why the two cmdlets are so often chained back to back in the same pipeline.

🏏

Cricket analogy: Select-Object is like a scorecard printout that only prints Name and Runs columns, hiding fielding and bowling stats, while Where-Object decides which players' rows appear at all.

Think of Where-Object as choosing rows and Select-Object as choosing columns. A typical reporting pipeline filters first with Where-Object to shrink the data set, then trims it with Select-Object to shrink the shape of each remaining object.

Simplified Syntax and Performance

Modern PowerShell allows a shorthand comparison syntax, Where-Object Status -eq 'Running', without a script block or $_, which reads more like natural language for simple single-condition filters. For performance-sensitive scripts, filter as early and as close to the data source as possible: many cmdlets, such as Get-ChildItem -Filter or Get-ADUser -LDAPFilter, can filter at the provider or server level, avoiding the cost of pulling an entire unfiltered data set into PowerShell before Where-Object even runs.

🏏

Cricket analogy: Filtering early with a bowler's own line-and-length rather than relying on fielders to clean up later is like the filter-left principle — cut unwanted data as close to the source as possible.

When a cmdlet offers a native -Filter or server-side filtering parameter, prefer it over piping unfiltered results into Where-Object. Pulling every object across the network or off disk before filtering locally can be dramatically slower on large data sets such as Active Directory queries or big file systems.

  • Where-Object keeps only the pipeline objects that satisfy a script-block condition.
  • Comparison operators are words: -eq, -ne, -gt, -lt, -like, -match, combined with -and, -or, -not.
  • Select-Object -Property trims which fields survive; -First/-Last/-Unique slice or de-duplicate the stream.
  • Where-Object filters rows; Select-Object shapes columns — the two are commonly chained together.
  • A simplified Where-Object syntax skips the script block for simple single-condition comparisons.
  • Filter as early and as close to the data source as possible, using native -Filter parameters when available.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#PowerShellStudyNotes#FilteringAndSelecting#Filtering#Selecting#Where#Object#StudyNotes#SkillVeris#ExamPrep