5

I'm trying to find a single line of code recursively using powershell.

To look for the line "TODO" in a known file I can do:

get-content ActivityLibrary\Accept.cs | select-string TODO

But I don't want to explicitly type every directory\file. I would like to pipe a series of filenames from get-childitem like this:

gci -filter *.cs -name -recurse | gc | select-string TODO

But then I see this error:

Get-Content : The input object cannot be bound to any parameters for the comman d either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:1 char:37

What am I doing wrong?

4

1 回答 1

8

您需要删除 -Name 开关。它只输出文件名,而不是文件对象。您还可以直接通过管道连接到 Select-String 并删除“gc”。

于 2012-12-17T15:12:25.993 回答