Filtering
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,-neequal / not equal-gt,-lt,-ge,-lenumeric comparisons-like/-matchfor patterns- Prefix with
-notor use-notliketo 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.