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)

2

Don't you want to do:

Invoke-Command -ComputerName localhost { cmd /c echo "hello"} | select-string "hello"
  • 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 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 user.name@domain.tld 
    { cmd /c echo "hello" | select-string hello | out-string }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.