PowerShell Direct lets you to manage your VMs whether or not you have network connectivity, just as long as your virtual machines are located on your Hyper-V host! This new feature has been introduced to simplify your daily tasks because you don’t need any network connectivity on your VMs. However, you can only use PowerShell Direct to remotely manage:

  • Windows 10 virtual machine
  • or Windows Server 2016 virtual machine

From:

Protect Your Data with BDRSuite

Cost-Effective Backup Solution for VMs, Servers, Endpoints, Cloud VMs & SaaS applications. Supports On-Premise, Remote, Hybrid and Cloud Backup, including Disaster Recovery, Ransomware Defense & more!
  • Windows 10 Hyper-V host
  • or Windows Server 2016 Hyper-V host

If you are wondering what about the older virtual machines? Well, you must still use Virtual Machine Connection (VMConnect tool).

How does it work?

PowerShell is able to access the virtual machine using the Virtual Machine Bus (Acronym is VMBus). The VMBus is a logical inter-partition communication channel and allows the Hyper-V host to communicate with VMs located on the Hyper-V host. It means that Hyper-V host will bypass any device emulation layer and this makes the communication more efficient but requires that virtual machines are VMBus aware.

Download Banner

To better understand, here is a schema published on MSDN website by Microsoft.

Hyper-V VMs with PowerShell

Of course, in a cluster architecture, PowerShell Direct works per host. It means that you must connect to each node before using PowerShell Direct.

The syntax

Before describing how to use PowerShell Direct, you must know what is a PowerShell Session?

The most basic method of using PowerShell to perform management tasks against remote machines (Windows Workstations or Windows Servers), is using the PowerShell Sessions.

PowerShell remoting relies on a standards-based protocol named Web Services for Management (WS-Man). This protocol is implemented in Windows as Windows Remote Management (WinRM). Let’s check into the Windows Services MMC, that you can see this service:

Hyper-V VMs with PowerShell

WS-Management is a standard web services protocol used for remote software and hardware management. The WinRM service listens on the network for WS-Management requests and processes them. The WinRM service provides access to WMI data and enables event collection. Event collection and subscription to events require that the service is running. WinRM messages use HTTP and HTTPS as transports.

In Windows Server 2012 and later, PowerShell remoting is enabled by default, so you don’t need to do anything. In the other Windows Operating Systems, the quickest way to enable PowerShell remoting is to run the following command:

Hyper-V VMs with PowerShell

That’s cool, remoting is enabled! Now just suppose you want to connect remotely on a server named “SRV01”. Within your PowerShell console, you will run the following command:

Hyper-V VMs with PowerShell

The first command uses the Enter-PSSession cmdlet to start an interactive session on SRV01 which is my remote computer. When the session starts, the command prompt changes to include the computer name. It means that you are connected on the remote machine.

Now, all the results are displayed in your PowerShell console.

Let’s imagine I disable the network adapter on SRV01, then I cannot connect to the server without PowerShell Direct:

Hyper-V VMs with PowerShell

So, let’s examine the PowerShell Direct syntax. Basically, this is the same syntax as a PowerShell session, with the only difference that the -VMName parameter is used instead of –ComputerName parameter:

Hyper-V VMs with PowerShell

Please note that you can use the –VMGuid parameter instead of –VMName parameter.

What is the difference between –ComputerName and –VMName parameters?

By adding the –VMName parameter, it means that Hyper-V will use PowerShell Direct instead of standard network connectivity. That’s very simple! So you can easily switch between both modes.

For those who don’t want to open an interactive session on the virtual machine, you can run a single command using the Invoke-Command cmdlet:

Hyper-V VMs with PowerShell

You can easily use the Get-VM cmdlet to get information such as:

  • VM Name
  • VM ID

Hyper-V VMs with PowerShell

You can use a variable to store your credential in order to reuse them easily:

Hyper-V VMs with PowerShell

How to know which VMs are compatible with PowerShell Direct?

You must identify the virtual machine using the “Get-VM” cmdlet. Next, you must check the VM version. Here, the version 8.0 indicates that it is compatible with PowerShell Direct:

Hyper-V VMs with PowerShell

Another point you need to check is the “Guest Services” option that allows you to copy files between the Hyper-V host and the virtual machine:

Hyper-V VMs with PowerShell

If the ‘Guest Services’ option is not active, it can be enabled via PowerShell:

Hyper-V VMs with PowerShell

Conclusion

PowerShell Direct is one of the new feature that allows you to interact with any virtual machines located on the Hyper-V host. The only thing to check is the OS version because it works only on Windows 10 and Windows 2016. PowerShell Direct is a great help for Hyper-V administrators.

Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.

Rate this post