Here is a very simple solution:
$SearchInDirectory = "C:\SearchingFolder";
$SearchForString = "Banana"; #String for searching
$SearchInFormats = "*.asp", "*.txt", "*.js"; #If empty will search in all file formats
echo 'Searching in progress...'
Get-ChildItem $SearchInDirectory -include $SearchInFormats -recurse | Select-String -pattern $SearchForString -SimpleMatch | group path | select name
It searches (recursively) in all directories and sub-directories for all the results and then prints them, so if you have a lot of files and directories it may take some time. Also, you can specify the file types you need to check (but not necessarily).
And also, I have a script that puts the results into file:
$SearchInDirectory = "C:\SearchingFolder";
$SearchForString = "Banana"; #String for searching
$SearchInFormats = "*.asp", "*.txt", "*.js"; #You can specify the file types
$PutSearchResultsInFile = ""; #link to a file or if blank - the results to be displayed on screen
Cls;
function SearchFilesByString_results () {
Get-ChildItem $SearchInDirectory -include $SearchInFormats -recurse | Select-String -pattern $SearchForString -SimpleMatch | group path | select name
}
if($PutSearchResultsInFile){
if(!(Test-Path -Path $PutSearchResultsInFile)){
New-Item $PutSearchResultsInFile -itemType "file" -confirm:$false | Out-Null
echo "`nNew file created. `n";
}
echo "Searching in progress... `n";
SearchFilesByString_results > $PutSearchResultsInFile;
echo "Search completed! Find results here: " $PutSearchResultsInFile "`n";
} else {
echo "`nSearching in progress.... `n";
SearchFilesByString_results
echo "`nSearch completed! `n";
}
Hope it helps! :)