Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

piping files to get-content

Tags:

powershell

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?

like image 821
micahhoover Avatar asked Dec 17 '12 15:12

micahhoover


1 Answers

You need to remove the -Name switch. It outputs just file names, not file objects. And you can also pipe directly to Select-String and drop 'gc'.

like image 69
Shay Levy Avatar answered Oct 11 '22 03:10

Shay Levy