Q
Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

How do I enable and use PowerShell Direct?

The Windows Server 2016 PowerShell Direct feature solves common management problems by eliminating the need for network connection or security policy modification when executing PowerShell commands.

Hyper-V administrators rely on remote management tools, such as Remote Desk Protocol or Virtual Machine Connect,...

if they need to execute PowerShell commands inside a Hyper-V VM. Although you can use the PowerShell Remoting feature to connect to a VM running on a Hyper-V host and execute commands remotely, this requires a working network connection, open network ports between the source and destination, and a series of PowerShell remote commands.

Windows Server 2016 Hyper-V hosts will help Hyper-V administrators solve common VM management problems. Starting with Windows Server 2016, you will be able to interact with VMs running on a Windows Server 2016 Hyper-V host in an easier, more reliable way. Before Windows Server 2016, a network connection and a modifying firewall configuration were necessary to run PowerShell commands inside a VM. Using the PowerShell Direct feature of Windows Server 2016, you can execute Windows PowerShell commands inside a VM from the Hyper-V host operating system (OS) without any network connection or modifying the organizational security policies.

There are a few prerequisites for using the PowerShell Direct feature. First, VMs and the Hyper-V host must be running Windows 10 or Windows Server 2016. Next, you must make sure that you are logged on to the Windows Server 2016 Hyper-V host using Hyper-V administrator. All VMs must run on the "local" Hyper-V host and, finally, PowerShell must be installed in the VM.

It is important to note that PowerShell Direct is enabled by default on Windows Server 2016 Hyper-V hosts. The hypervisor code in Windows Server 2016 has been modified to include the PowerShell Direct feature, while the Hyper-V parent partition implements a PowerShell Direct component that runs under the VMMS.exe process. PowerShell Direct uses VMBUS communication channel to communicate with the VMs running on the local Hyper-V host.

There are two ways to run PowerShell commands using the PowerShell Direct feature. For the first method, you must begin by entering the following command:

            Enter-PSSession –VMName <VMName>

This command allows you to create a PowerShell interactive session against the VM name specified in the –VMName parameter. After running this command, you can use the Get-Service command or run any other PowerShell command. When finished, run the Exit-PSSession command.

When you implement the above series of PowerShell commands on a Hyper-V host, the PowerShell cmdlet (Get-Service) is executed inside the VM and the output is shown in the PowerShell window of the Hyper-V host. The second method involves using an Invoke-Command cmdlet to allow you to run a PowerShell command or a script against the VM specified in the –VMName parameter. Here is an example of using the Invoke-Command cmdlet:

Invoke-Command –VMName TestVM –FilePath C:\VMScripts\Script1.PS1
Invoke-Command –VMName TestVM –ScriptBlock { Get-Process }

At present, the PowerShell Direct feature isn't supported on VMs running on the remote Hyper-V host; the VMs must be running locally. It is also worth mentioning that the PowerShell Direct feature only works for VMs running Windows 10 and later OSes.

Next Steps

Anticipation builds for Windows Server 2016 features

Ensuring a painless Windows Server 2016 upgrade

Why you should consider upgrading Windows Server

This was last published in January 2016

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

Other than PowerShell Direct, what new Windows Server 2016 features are you most anticipating?
Cancel

-ADS BY GOOGLE

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close