Multiple commands within ScriptBlock
I am able to reproduce this.. it only returns the first statement. It's not the semicolon, it does the same thing if you use like breaks.
These options work:
Invoke-Command -ComputerName computer -ScriptBlock {
(Get-Service)
Get-Process
}
Or this curiously:
Invoke-Command -ComputerName computer -ScriptBlock {
& {
Get-Service
Get-Process
}
}
Since wrapping one of them in ( )
works I feel like this must be some quirk of the pipeline but I haven't been able to figure out exactly what it's doing yet.
Update:
After reading your comment that your source machine was running v5 and the remote v2, I realized that my testing did the same.
When I remoted from the v5 into itself, the 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, but it seems like it really may be a bug from v5 to v2.
You could try to separate them by a comma which would make the results an array that you could then look at by each index.
$Results = Invoke-Command -ComputerName cas-bkupexec -ScriptBlock { (Get-Service), (Get-Process) }
#Services
$Results[0]
#Processes
$Results[1]