Use Where-Object to Filter Results

by Mar 15, 2011

You can always use Where-Object when you need to filter results. This cmdlet expects a filter script to determine the results you want. Here are some examples:
Try this to find only files greater than 1MB:

dir $env:windir | Where-Object { $_.Length -gt 1MB }


Use this when you need to find all processes with more than 20 seconds CPU time:

Get-Process | Where-Object { $_.CPU -gt 20 }


And to list all services not currently running, this is the code you will need:

Get-Service | Where-Object { $_.Status -eq 'Stopped' }



Twitter This Tip!
ReTweet this Tip!