Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Create Function List and Find PowerShell Files

$
0
0

SummaryUse Windows PowerShell to create a function list and find files.

Hey, Scripting Guy! Question How can I use Windows PowerShell to avoid repetitively typing “ls . –r *.ps1” to get a list of PowerShell files and then
           “ls . –r *.ps1 | sls function” to search the content of those files for a string?

Hey, Scripting Guy! Answer Add this function to your PowerShell profile:

function fps ($find) {    

    "Get-ChildItem . -Recurse *.ps1 $(if($find) { "| Select-String $find" })" |

        Invoke-Expression

}

Then, if you type `fps`, you’ll get a list of .ps1 files. To search for the string functions in each file, type `fps function`.


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>