1

I am trying to pipe into powershell commands that I am dynamically retrieving. So for example, if I get this command object

$ls = Get-Command 'Get-ChildItem'

How do I pipe anything to it?

I have tried:

'.\' | $ls

but I get an error that Expressions are only allowed as the first element of a pipeline.

Josh Petitt
  • 9,371
  • 12
  • 56
  • 104
  • What exactly are you trying to achieve? I'm afraid your question doesn't make a lot of sense to me! It's worth noting that the `Get-Command` CmdLet returns an object, not a reference to the function! https://technet.microsoft.com/en-us/library/ee176842.aspx – gvee May 09 '17 at 12:49
  • 6
    Invocation operator `&` or `.` to the rescue: `'.\' | & $ls`. – user4003407 May 09 '17 at 12:50
  • Exactly, I have a command object that I get dynamically from a string. I want to pass the contents of the pipeline to this command. – Josh Petitt May 09 '17 at 12:50
  • Thanks PetSerAl, that was easy! If you want to add as answer, I'll accept – Josh Petitt May 09 '17 at 12:51
  • Possible duplicate of [What's the equivalent of xargs in PowerShell?](http://stackoverflow.com/q/36428949/1630171) – Ansgar Wiechers May 09 '17 at 13:00

0 Answers0