Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

share|improve this question
add comment

2 Answers

Don't you want to do:

Invoke-Command -ComputerName localhost { cmd /c echo "hello"} | select-string "hello"
share|improve this answer
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
add comment

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 }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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