开发者

PowerShell command to parameterised PowerShell function?

开发者 https://www.devze.com 2022-12-15 11:23 出处:网络
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\"

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 rememb开发者_如何学运维er 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.


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
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号