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 [email protected] { 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)

2 Answers 2

2

Don't you want to do:

Invoke-Command -ComputerName localhost { cmd /c echo "hello"} | select-string "hello"
1
  • 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. Apr 20, 2012 at 5: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 [email protected] 
    { cmd /c echo "hello" | select-string hello | out-string }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .