powershell - Multiple commands within ScriptBlock -


i'm having trouble running multiple commands within scriptblock parameter. documentation points towards using semicolon separation between cmdlets. using same methodology of separating cmdlets via semicolon works on local machine, not on remote machine through invoke-command.

for example, below code return result of get-service, , not get-process.

invoke-command -computername cas-bkupexec -scriptblock { get-service;  get-process } 

how can achieve desired result of both commands running , receive output of each?

i able reproduce this.. returns first statement. it's not semicolon, same thing if use breaks.

these options work:

invoke-command -computername computer -scriptblock {     (get-service)     get-process } 

or curiously:

invoke-command -computername computer -scriptblock {     & {          get-service         get-process     } } 

since wrapping 1 of them in ( ) works feel must quirk of pipeline haven't been able figure out it's doing yet.

update:

after reading comment source machine running v5 , remote v2, realized testing did same.

when remoted v5 itself, issue disappeared.

remoting from:

v2 -> v5: no issue v2 -> itself: no issue v2 -> other v2: no issue v3 -> v2: no issue v3 -> v5: no issue v3 -> itself: no issue v4 -> v2: no issue v4 -> v3: no issue v4 -> itself: no issue v4 -> v5: no issue 

not every combination here, seems may bug v5 v2.


Comments