2

In powershell (2.0) the following works nice and fine: cmd /c echo "hello" | select-string hello

Outputs "hello".

When running this in remoting mode, text is not printed:

Invoke-Command -ComputerName myserver -Credential user.name@domain.tld { cmd /c echo "hello" | select-string hello }

Why, and how do I grep text of commands (exefiles) in remoting mode? (windows7 on client, 2008r2 on server. Commands can run fine, ports are open, etc)

Mike Pennington
  • 8,266
  • 9
  • 41
  • 86

2 Answers2

2

Don't you want to do:

Invoke-Command -ComputerName localhost { cmd /c echo "hello"} | select-string "hello"
manojlds
  • 346
  • 2
  • 5
  • 1
    No, the actual script block which is executed on the remote server is much larger than this example, and from one single of the commands which are executed I want to minimize it's console output. – SomeDude123 Apr 20 '12 at 05:08
1

The output of Select-String is not a string, but a MatchInfo, which can't be returned over the Invoke-Command connection.

Simply pipe the results of Select-String to Out-String, and you will get your output~:

Invoke-Command -ComputerName myserver -Credential user.name@domain.tld 
    { cmd /c echo "hello" | select-string hello | out-string }
AakashM
  • 121
  • 6