PowerShell Script Searcher

If you are like me, then you are writing PowerShell scripts for pretty much everything now-a-days, and even if you aren’t like me, chances are you still have a bunch of PowerShell scripts saved on your computer. I can’t tell you how many times I’m writing a script, and I realize that I’ve already written something similar. However, at my last count I had close to 4,000 PowerShell scripts on my computer. As you can imagine finding the one I’m thinking about can be kind of difficult. So, that is why I’ve written a function that I can use to search all the PowerShell scripts on my computer for a specific word or phrase.

All you have to do is pass the string to search for and the folder to look in. It will then find all the ps1 and psm1 files in that folder. Then it will check each one for the string you specified. For all matches, it will display the full path to the script and the last time it was written to.

If you don’t supply a value for path it will default to the path of your user profile. You can also specify whether or not to perform a recursive search. By default, the search is not recursive, meaning it will only search the folder provided in the path, and not the sub-folders. If you provide the Recurse parameter it will also search the sub-folders.

You can also use the -Verbose parameter to display the lines that matched your string in each of the files it found.

You can download the most current version of the script from my GitHub Gist, or copy it from below.


Leave a Reply


We use cookies to ensure the best possible experience on our website. Detailed information on the use of cookies on this site is provided in our Privacy and Cookie Policy. Further instruction on how to disable our cookies can be found there.