Simple Search for Text – Powershell

I was given the task to search which file contained a particular name in a folder that contained about 200 pages of extensions htm and html pages. The webmaster needed to figure out the location of the text in question how many pages were affected so that he can update them right away. What the script does is simple and hopefully it helps someone.

This is a small script that allows you to search a directory for specific text within a txt, htm and html file.


The test directory contains the following files

The script

# Script to scan files in a directory for keywords

$StartFolder = “C:\temp\”

$files = Get-ChildItem “C:\temp” -name

foreach ($file in $files) {

$FilePath = $StartFolder+$file

#Search for keyword and output results to a txt file

Select-String -Path $FilePath -pattern
Photosynth |
C:\Temp\report.txt -Append

# Display Files in current folder



Scanned Files

Output in txt file


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