views:

60

answers:

1

I'm not so hot with PowerShell yet, but have managed to get this command to work quite nicely:

get-childitem "C:\Code\WC1" -Recurse | select-string "insert into\s+my_table"

Thing is, I know I'm going to struggle to remember this, so how can I make it into a function where the path supplied to get-childitem and the search regex are parameters?

I'm using PowerShell 2.0.

+1  A: 
Function Find-Code([string] $path, [string] $pattern)
{
    get-childitem $path -Recurse | select-string $pattern
}

You can put this in your PowerShell Profile. An easy way to do this is to edit the $profile file (run something like notepad $profile from your PowerShell prompt) and just paste the text right in.

Blair Conrad
+1 for your answer, an I'll accept it too if you can tell me where I put it so that it's always available in a new PS session...
Neil Barnwell
Thanks for the update!
Neil Barnwell
My pleasure. I'm glad you found my answer useful.
Blair Conrad

related questions