Hyper-V 2016 Cool Feature: PowerShell Direct

March 31, 2017

PowerShell is a great tool for remotely administering and managing virtual and physical machines. Physical machines do offer the ability of connecting to their DRAC, iLO or Remote KVM to perform actions when there is zero network connectivity. PowerShell Direct gives IT Professionals the ability to run remote PowerShell commands against a guest Hyper-V VM without the IP network requirement. This feature is supported on Hyper-V hosts that are running Windows 10 or Windows Server 2016. The guest VM must also be running Windows 10 or Windows Server 2016 or greater in order to be managed.

PowerShell Direct utilizes the VMBus of the Hyper-V host to communicate with the Guest VM. Traditional PowerShell requires PSRemoting to be enabled and the VMs to have network connectivity. With PowerShell Direct, one could boot up a VM, connect to the VM, configure networking and add to the domain with ease. Microsoft has introduced 2 new variables into PowerShell -VMName and -VMGuid. When connecting to the VMs, first log into the Hyper-V host or Windows 10 desktop. It is possible to use PSRemoting to connect to the parent host and within the PSRemote session then enter PowerShell Direct.

PowerShell

1

Enter-PSSession

Enter-PSSession is an interactive session to the remote VM. Through this method, your connection remains sticky until you Exit the PowerShell session or close the PowerShell window.

PowerShell

1

2

3

Enter-PSSession-VMNameVM_Name-Credentiallocalhostadministrator

<Run your commands>

Exit-PSSession

Another method to execute commands within a remote VM is Invoke-Command. Invoke-Command uses PowerShell Direct and is the preferred connection method if executing an entire script. Get-Credential is used to store the credentials within the session, this is used when running multiple lines or commands within a single session.

PowerShell Direct is a brand new feature within Windows Server 2016 that allows the Hyper-V host machine to interact with the Guest VMs without any type of network connectivity. One caveat is that if you’re leveraging Shielded VMs, another new feature in Windows Server 2016 – you’re unable to connect to the VM using PowerShell Direct. I’ll cover Shielded VMs in the next blog!

About The Author

Search

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Email Address

About Clint

Clint Wyckoff is a Senior Cloud Technical Account Manager at Amazon Web Services (AWS). He is an avid technologist and virtualization fanatic with more than a decade of enterprise data center architecture experience. Clint is an energetic and engaging speaker and places a large emphasis on solving the real-world challenges IT professionals face. Additionally, he is a 2x Microsoft Most Valuable Professional (MVP) for Cloud and Datacenter Management, VMware vExpert for 2015, 2016, 2017 & 2018 as well as Co-Founder and Leader of vBrisket. Clint is also an AWS Certified Solutions Architect, Veeam Certified Engineer (VCME) and Microsoft Certified Professional (MCP).