With the arrival of Windows Server 2016 and Windows 10, Microsoft has introduced a new cool feature, very interesting for anyone who want to do remote tasks with virtual machines. PowerShell Direct allows IT admins to run PowerShell sessions inside a virtual machine from Hyper-V in a direct mode, without networking or similar. This means you can invoke a script also if the network is not available; or whether the hosts are separated from server/clients or there’s no way to open a remote session of PowerShell due to security policies. For this reason, PowerShell Direct is a “good to know”.


To use PowerShell Direct is necessary to check these requirements:

  • The Virtual Machine must running Windows 10 or Windows Server 2016
  • The Virtual Machine must running in the same host that you want to use to open the session
  • The Virtual Machine must have at least a valid user profile configured
  • The session must be opened as local admin of Hyper-V host
  • It’s necessary to insert valid credentials for Virtual Machine

Create a Remote Session

To open a new remote session, use the command Enter-PSSession -VMName yourvm – as shown in figure 1.


Figure 1 – New PS Session

Once you are inside the session, you are able to work into the virtual machine and run PowerShell cmdlets in the same way of local, this means that you can use the PS Modules installed; as shown in figure 2, we can use docker commands without problems although the role is not present into Hyper-V host.


Figure 2 – Remote Commands

NB: Keep in mind that all the connections based on Enter-PSSession are temporary and this means that if you close the window, it will be necessary to enter again the credentials.

Run Complex Commands

The classic connection can be used to run easy and simple tasks while if you need to execute advanced scripts, it’s possible use the Invoke-Command. This cmdlet is perfect to run a complex script stored into a repository (locally or remotely). It’s possible use two kind of ways:

  • Command: Invoke-Command -VMName nomevm -ScriptBlock { Get-Service }
  • Script: Invoke-Command -VMName nomevm -FilePath “C:\hyperv-folder\script.ps1”


Figure 3 – Invoke Command

Copy Files

Not only commands or scripts, but also a way to transfer files from host to the virtual machine. This can be achieved with the “Copy-Item” cmdlet,  but it is required to open a persistent session in order to avoid interruption in case you close the window; the goal is to use the same session every time without re-insert the credentials. This is an example:

$VM = New-PSSession -VMName nomevm -Credential (Get-Credential)

Copy-Item -ToSession $VM -Path C:\hyperv-folder\app.exe -Destination C:\guest-vm\


Figure 4 – File Copy

The performance behind this task are very interesting because thanks to the VMBus, we can jump all the drivers and the layers to allow the communication. The result is an high speed copy process, but don’t forget to consider what kind of file you want to transfer and also the VM performance (a .vhdx file located into an SSD is much faster than a file located on a HDD).


PowerShell Direct allows IT admins to execute and automate the management tasks without the requirement to interact with operating system via GUI.

(Italian, French, German, Spanish, Portuguese (Brazil))

PowerShell Direct: a new way to manage your Hyper-V VMs
Iperius IT Team

PLEASE NOTE: if you need technical support or have any sales or technical question, don't use comments. Instead open a TICKET here: https://support.iperius.net


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


PLEASE NOTE: if you need technical support or have any sales or technical question, don't use comments. Instead open a TICKET here: https://support.iperius.net