gci -recurse -filter *.sql | select-string -pattern "YOUR SEARCH STRING" -list
OK that’s it hope you like this post, see you next week.
No seriously lets take a quick look this, gci also known as Get-ChildItem for the current location, recusing through any and all lower level directories. Filtering on any file that ends with the .sql extension. Passing all of these objects to the select-string function looking inside each file for a pattern of what replaces the “YOUR SEARCH STRING” if it exists returning it in the “list” manner which is; location of the file from the present location, name of the file, the line number of the first occurrence in the file, and the line itself.
Why am I going over this because this kind of simple PowerShell one liner can help a DBA or a SQL Developer find a key script in seconds. Of course you have to have a little organization of your SQL files and you have to know what your looking for. This can be used for a lot more than SQL files. PowerShell is knocking, its going to come in, take advantage of it!