Where-Object Examples: Filter Anything in PowerShell
Where-Object is how you say "only the ones that match." It's the filter you'll use most, so it's worth getting comfortable with both ways to write it.
The simple syntax
For a single condition, name the property, an operator, and a value. It reads almost like English.
Get-Service | Where-Object Status -eq Running
Get-ChildItem | Where-Object Length -gt 1MB
The script block syntax
When you need more than one condition, use braces. $_ stands for the current item. The alias ? does the same job.
Get-Process | Where-Object { $_.CPU -gt 50 -and $_.Name -like 'chr*' }
Operators worth memorizing
-eq equals, -ne not equal, -gt and -lt for greater and less, -like for wildcards, -match for regex, -contains for checking a list. Comparisons ignore case unless you use the c versions like -ceq.
'PowerShell' -like 'Power*'
'abc123' -match '\d+'
Practice it for real. shellreps has hands-on PowerShell labs that run in your browser, no install. The first one is free, no signup. The terminal mimics PowerShell syntax so the habits carry over, though it isn't Microsoft's PowerShell itself.