PowerShell One Liner For Showing All Files In A Folder That Contain A String

Quick one today, this is probably the third or fourth time in the last few months I’ve needed to parse multiple files searching for a string, and each time I spend a little bit more time thinking about how to quickly do it than I’d like. So here it is for future reference, a quick one liner to print out the files that contain a string in a folder.

Get-ChildItem -File -Recurse | % { if ((Get-Content $_.FullName) -match "YOUR SEARCH STRING HERE") {$_.FullName}}

This assumes there are only text files in the folder, I recommend adding filters to Get-ChildItem if you have other file types too.

Now I just need to remember that I wrote this next time I need it…

If you enjoyed this post consider sharing it on , , , or , and .