Filtering

View saved

Where-Object

Keep only objects that match a condition.

Get-Process | Where-Object { $_.CPU -gt 10 }
Get-ChildItem | Where-Object Name -like "*.txt"

Comparison operators

  • -eq, -ne equal / not equal
  • -gt, -lt, -ge, -le numeric comparisons
  • -like / -match for patterns
  • Prefix with -not or use -notlike to invert

Filter early when possible

Some cmdlets accept filter parameters that work at the source and are faster than piping everything.

Get-Service -Name wuauserv

Combine conditions

Use -and / -or inside the script block.

Get-ChildItem -File | Where-Object { $_.Length -gt 1KB -and $_.Extension -eq ".log" }

Comments

One comment per signed-in account. Comments are saved with this page’s URL.