Find-Text Powershell function to find text in files, folders, subfolders

This function will search for the input text in the files under the input folders and their subfolders. It can bedownloaded from the Microsoft Script Center Repository.

It can search for more than one text pattern – separated by commas. For example:

Find-Text -TextPattern numlock,Cheese
This example will seach for the text patterns ‘numlock’ and ‘cheese’ in all files under the current folder and its subfolders.
If it does not find any matches it will display a message like:
Search patterns are not case sensitive. So searching on “numlock” will return results including “numlock” and “NumLokc”
You can limit the search to certain file types by using the -FilePattern parameter. For example:
Find-text -TextPattern numlock,boutros -FolderName \\MyServer\install\scripts -FilePattern *.txt,*.csv,*.ps1
This example will search for “numlock” and “boutros” in files with the text patterns *.txt,*.csv,*.ps1 under the folder \\MyServer\install\scripts and its subfolders

Function will display a progress bar indicating text patterns it’s searching for, file it’s currently searching in, and file number out of total number of files. Function returns a PS object with 2 properties: String, and File. String is the text pattern found, and File is the full path where the text pattern was found:


Function output can be displayed to the screen as in:

$Found = Find-text "numlock","boutros" "\\xHost15\install\scripts",".\test"  
if ($Found) { $Found | Out-GridView }
Output will look like:
Function output can be exported to CSV for viewing/processing in MS Excel for example:
$Found = Find-text "numlock","boutros" "\\xHost15\install\scripts",".\test"  
if ($Found) { $Found | Export-CSV ".\Found.csv" -NoTypeInformation }
Output will look like:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.