Mimicking grep in Windows with Powershell

If there’s one UNIX command that’s ever needed to exist on Windows, it would have to be grep. In past years Windows users have needed special programs to mimic this capability. However with the introduction of Powershell, Windows users can now perform grep-like searches natively.

If you need to find a list of files that contain a certain string then this little snippet should do the job.

Get-ChildItem C:\path\to\search -Recurse -Include *.* | Select-String "string to find" | Select-Object -Unique Path

Just modify the C:\path\to\search to match whatever location you want to search (or leave it out to search the directory you’re currently in) and replace string to find with what you’re looking for. Then run it and it’ll print out the filename for any matches it finds.

  • Bruce Richardson

    Or you could use the find command. It’s not grep but it does a good 60% of the job.