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.

2 Answers 2

2

more commonly these days the parameters are being called after the function declaration e.g.

Function Find-Code { param([string] $path, [string] $pattern) get-childitem $path -Recurse | select-string $pattern } 
Sign up to request clarification or add additional context in comments.

Comments

1
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.

2 Comments

+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...
My pleasure. I'm glad you found my answer useful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.