Filter PowerShell Results Fast and Text-Based

by Mar 25, 2011

Take a look at this simple filter called grep:

filter grep($keyword) { if ( ($_ | Out-String) -like "*$keyword*") { $_ } }

And here are some samples showing how easy it is to filter results using plain text keywords:

PS > Get-Service | grep running
PS > Dir $env:windir | grep .exe
PS > dir $env:windir | grep 14.07.2009
PS > Get-Alias | grep child

As you can see, while the filtering is based on simple plain text keywords, the results are still rich objects!

 

Twitter This Tip!
ReTweet this Tip!