Filter PowerShell Results Fast and Text-Based

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!


Posted Mar 25 2011, 08:00 AM by ps1

Comments

draugasvd wrote re: Filter PowerShell Results Fast and Text-Based
on 03-25-2011 4:12 PM

this good one!

Copyright 2012 PowerShell.com. All rights reserved.