Skip to content
← All tips

Search for text in every file of a folder with PowerShell

Which file in the solution was using that column? Where did that old URL end up? You don’t need Visual Studio for this, one line of PowerShell will do:

cd "C:\path\to\my\project"
Get-ChildItem -Recurse -File | Select-String -Pattern "new_field" -List | Select-Object Path

-List stops at the first match in each file, which is exactly what you want when you only need to know which files contain the text. To see every matching line with its number, drop -List and the trailing | Select-Object Path. If you only care about certain file types, filter with Get-ChildItem -Recurse -Include *.cs,*.js.

I almost always leave out bin, obj and node_modules. Otherwise the search takes forever and the output is full of results you don’t care about:

Get-ChildItem -Recurse -File | Where-Object FullName -notmatch '\\(bin|obj|node_modules)\\' | Select-String -Pattern "new_field" -List | Select-Object Path
Share:LinkedInX

Did it help?

If you need help with this in your project, write to me.

More tips