To find a string inside files in a directory tree with PowerShell, move to the root of the desired directory and run:
Get-ChildItem -Recurse -Filter *.config | Select-String -Pattern "find_for_this_string"
This searches for find_for_this_string inside files of type *.config (e.g. web.config files), recursively from the current directory.
How it works
Get-ChildItemenumerates files;-Recursewalks subdirectories and-Filtermatches a single wildcard pattern (much faster than-Include, and without its wildcard-path quirks).Select-Stringis the PowerShell equivalent ofgrep: it searches file contents for a pattern and outputs the match, line number, and filename.
Reading this in 2026
The command still works unchanged on PowerShell 7.x on Windows, Linux, and macOS (the modern -Filter form above is the one to memorize). A few refinements worth knowing:
- Drop the wildcard dance: modern
Get-ChildItem -Recurse -Filter *.configis cleaner and faster than.\*plus-Include. - Search everything: omit
-Include/-Filterentirely to search all files; add-SimpleMatchtoSelect-Stringwhen your pattern is a literal string, not a regex. - Case sensitivity:
Select-Stringis case-insensitive by default; use-CaseSensitivewhen that matters. - On Linux/macOS,
grep -r "find_for_this_string" --include='*.config' .remains the native habit — but PowerShell’s cross-platform support means the same muscle memory works everywhere.