Introduction
Use Where-Object to pick only the items you want from a list or collection. It helps you filter data easily.
collection | Where-Object { condition }Get-Process | Where-Object { $_.CPU -gt 100 }Get-ChildItem | Where-Object { $_.Extension -eq ".txt" }$numbers = 1..10 $numbers | Where-Object { $_ % 2 -eq 0 }
$files = Get-ChildItem -Path .
$largeFiles = $files | Where-Object { $_.Length -gt 1000000 }
foreach ($file in $largeFiles) {
Write-Output $file.Name
}Where-Object cmdlet do in PowerShell?Where-Object?1..5 | Where-Object { $_ % 2 -eq 0 }Get-Service | Where-Object $_.Status -eq 'Running'
Get-ChildItem | Where-Object { $_.Length -gt 1048576 } | ??? What should replace ????Pass the test and this pattern moves unknown