PowerShell Remoting

While in Barcelona, I got a sneak peek at how PowerShell will – in a future version – handle remoting. It’s pretty cool. Say you start with this:

Get-Service

Simple enough, right? This uses gets a list of all services on the local computer. In fact, this runs in-process, meaning it executes within the current instance of PowerShell. Now try this:

powershell {Get-Service}

This executes a new instance of PowerShell, passing it a scriptblock containing “Get-Service.” The new instance executes the cmdlet and passes the resulting objects – not text, mind you, but objects – back to the original instance of the shell. The end result – what you get on the screen, that is – is the same, but it’s important to understand that Get-Service didn’t run inside the original shell process. It ran out of process, with the results coming back into your shell.

A future version of PowerShell will allow this variant:

powershell {Get-Service} -computer Server2

See? This remotes the scriptblock to Server2, and returns the results to your original shell instance. In other words, you can execute anything you want to on the remote shell! Of course, PowerShell would have to be installed on the remote computer – which in itself presents some limitations. For example, “Longhorn” Server Core can’t run PowerShell (because Core doesn’t run the .NET Framework).

While we don’t have this capability yet, it’s neat to see that the PowerShell team is thinking about it, and that they’ve come up with such an elegant solution.