Interactive remoting in CTP3

Rate This
  • Comments 18

Today let's talk about one of the cool new features of Windows PowerShell V2 - Interactive Remoting.

Let’s start with an example:

PS> $env:COMPUTERNAME # Check local computer name.                                                                      
PS> Enter-PSSession Vladimia06 # Remote to other computer.
[vladimia06]: PS C:\Users\Vladimia\Documents> $env:COMPUTERNAME # Check remote computer name.
[vladimia06]: PS C:\Users\Vladimia\Documents> $PSVersionTable # Check powershell version on remote computer.

Name Value
---- -----
CLRVersion 2.0.50727.3521
BuildVersion 6.1.7015.0
PSVersion 2.0
PSCompatibleVersions {1.0, 2.0}

[vladimia06]: PS C:\Users\Vladimia\Documents> function prompt {} # See how prompt function is always prefixed by [<compu
tername>]: in interactive remoting.
[vladimia06]: PS>Exit-PSSession # Exit remote session.

As you can see Enter-PSSession starts interactive remoting session and Exit-PSSession takes you out of it. The aliases for these commands are etsn and exsn. You can also use exit keyword instead of Exit-PSSession.

Interactive remoting uses the same remoting infrastructure as other PowerShell remoting cmdlets. WinRM provides the transport and maintains a listener service, which is responsible for creation of the remote PowerShell sessions.

Similar to Invoke-Command, you can use computer name to establish remote connection. In that case remote PSSession is created implicitly for you when you enter and disposed of after you exit.

Alternatively, you can create a persistent session using New-PSSession command and use it with Enter-PSSession. In that case the session won’t be closed after you finish and you can enter it multiple times exactly when you need it.

PS> $s = nsn vladimia06  # Create a persistent remote session.                                                          
PS> etsn $s
[vladimia06]: PS C:\Users\Vladimia\Documents> $x = 123 # Create a variable.
[vladimia06]: PS C:\Users\Vladimia\Documents> exsn
PS> etsn $s
[vladimia06]: PS C:\Users\Vladimia\Documents> $x # Check that a variable is still there
[vladimia06]: PS C:\Users\Vladimia\Documents> exsn
PS> icm $s {$x} # The variable created in interactive remoting can also be accessed using remote invocation.
PS> rsn $s # Close the remote session.

Note that the variables that are created in remote session won’t be available in your local runspace when you exit. You need to use Invoke-Command to get them to the client side. The corresponding object will be serialized over the wire and reassembled on the other side. Primitive types will be restored as fully functional ‘live’ objects, but more complex object will be reduced to deserialized ‘property bags’. We will talk more on serialization in one of the next posts.

Try it, use it, love it!
Vladimir Averkin
Windows PowerShell Team

Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post
  • @Doug:

    You need to run Enable-PSRemoting -force

    @YL Woo:

    Please verify that you have correct version of WinRM installed (use Test-WSMan, the Stack value should be 2.0). Then check if winrm service is running and make sure you have run Enable-PSRemoting -force and added target computer to TrustedHosts.

    Note, that the first step to test remoting is to run New-PSSession without computer name. That will create a localhost connection, for which TrustedHosts is not needed.



  • Hiya,

    I had days of struggling trying to get bakground jobs to run on vista home premium - is it possible?  I downloaded the trial version of server 2008 & had it up & running in seconds.  I think its the over the top security in vista that is causing my problem - on trying to configure winrm I get that it doesnt have permission for localhost !

    Ive tried disabling UAC & the "neater" DWORD=0 stuff but all to no avail - have you any suggestions please.  Its the CTP3 versions I'm trying to install



  • Now they have interactive remoting working… I tell you something, PowerShell v2 is getting more and more

Page 2 of 2 (18 items) 12

Interactive remoting in CTP3