Search This Blog

Thursday, June 9, 2011

Grep'ing files in Windows 2008 with PowerShell

For the life of me I can't get the windows search function to work correctly under Windows 2008 to do full-text recursive searches of a directory tree -- supposedly you need to reset the folder options under Windows to search file contents but it just doesn't work right.

Here's a simple way to do it using PowerShell:



PS> get-childitem d:\ -include *.aspx -recurse select-string -pattern '.toggle'

Here I'm doing a recursive full-text search of a directory tree for files containing the string '.toggle' (it's a JQuery function I used sometime over the last year that I needed an example of).

This works well and, unlike the built-in Windows "search" function (quotes are intentional), its operations are transparent and actually work.

1 comment:

David Graper said...

Note: Include a pipe symbol:

get-childitem -include *.cs -recurse | select-string -pattern 'mypattern'