Skip to main content

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".

http://csharpening.net/?p=1781

MVP Kristian Nese explains PSDirect (awesome post).

http://kristiannese.blogspot.in/2015/08/explaining-powershell-direct.html

MVP Mark Scholman's post on PSDirect.

https://markscholman.com/2015/05/imagine-what-you-could-do-with-powershell-direct/

Popular posts from this blog

Test connectivity via a specific network interface

Recently while working on a Private cloud implementation, I came across a scenario where I needed to test connectivity of a node to the AD/DNS via multiple network adapters.  Many of us would know that having multiple network routes is usually done to take care of redundancy. So that if a network adapter goes down, one can use the other network interface to reach out to the node. In order to make it easy for everyone to follow along, below is an analogy for the above scenario: My laptop has multiple network adapters (say Wi-Fi and Ethernet) connected to the same network. Now how do I test connectivity to a Server on the network only over say Wi-Fi network adapter?

PowerShell + SCCM : Run CM cmdlets remotely

Today I saw a tweet about using implicit remoting to load the Configuration Manager on my machine by Justin Mathews . It caught my eye as I have never really tried it, but theoretically it can be done. Note - The second tweet says "Cannot find a provider with the name CMSite", resolution to which is in the Troubleshooting section at the end.

Azure DevOps Tips & Tricks - Find private REST APIs

Original source -  Azure DevOps Tip - Find private APIs Often working with Azure DevOps, I hit a wall trying to automate some tasks but there are no REST API's made public yet. It was one of those task of automating creation of Environments in multi-stage YAML based pipelines in AzDO. Quick research reveals that this has been requested in uservoice  (please upvote). Let's see one of the very simple ways to discover some of these APIs.