Wednesday, February 24, 2016

PowerShell : Nested Remoting (PSRemoting + PSDirect)

Well the title is interesting enough, right ?
I saw some interesting comments when I posted the below pic around the release of Server 2016 TP3 in our PowerShell FB group:

In this post, I try to tell how I use this simple trick in my everyday use.

Sometime while logging into work from Home over VPN with a really bad internet connection, I use this trick to remote into the Management VMs running on a Server 2016 to test things in my lab.

Connecting over RDP on a flaky network connection is a horrible experience, and most of my overnight explorations do not require a GUI ;)

There is this neat feature introduced in Server 2016 which you must have heard of PowerShell Direct. Before PSDirect, I would have to RDP to the Hyper-V host (not domain joined) and then connect to VM using VMConnect (sitting on internal network) and then run PS .

Below is a graphic on how I use PowerShell direct along with PowerShell remoting to manage my VMs now.

Note - The Hyper-V Host is not part of the domain, this is my Lab server. The VMs running inside are test VMs sitting on an internal network (can't remote into them from my Corporate network).

So below is the break down of the this really simple process:

  1. Connect to the my Hyper-V host running Server 2016 (TP4) using PowerShell remoting. I use IP address to connect to this host using PSRemoting (already added entry to Trusted hosts).

    Below is an animated gif showing this in action :

    No need for you to do it, if the machine is part of the domain (reachable using the Netbios name).
  2. Once I am dropped into an interactive PSRemoting session to my Hyper-V host, I use Enter-PSSession (using -VMName parameter) now to connect over PowerShell direct to my VM. This time I specify domain creds for my test domain to connect to the only DC running in my Lab.

  3.  The remote file editing feature of ISE can be used in this nested remoting (sort of) session too.

With this awesome new feature, now I save up my bandwidth while fooling around with PowerShell on my Lab server.

This brings me to the end of the post, check out the resources section for some awesome posts around PowerShell direct.

Resources :

MVP Adam Driscoll's post on the topic "Digging into PowerShell Direct".

MVP Kristian Nese explains PSDirect (awesome post).

MVP Mark Scholman's post on PSDirect.

No comments:

Post a Comment