Overview of PowerShell Direct in Hyper-V virtual machines

Posted: (EET/GMT+2)

 

PowerShell Direct lets you run PowerShell commands inside a Hyper-V virtual machine from the host, without opening network ports or configuring WinRM. It uses the Hyper-V integration channel to run the commands instead of relying on TCP/IP.

There are some requirements for PowerShell Direct (PSD) to work correctly:

  • You need Windows 10 or Windows Server 2016 (or later) with Hyper-V.
  • The Guest OS has to be Windows 10 or Windows Server 2016 or later.
  • You have local administrator credentials inside the guest.

To open an interactive session from the host:

Enter-PSSession -VMName "MyVM" -Credential (Get-Credential)

To run a single command:

Invoke-Command -VMName "MyVM" -Credential (Get-Credential) `
  -ScriptBlock { Get-Service | Where-Object Status -eq "Running" }

Because PowerShell Directdoes not depend on network connectivity, it can still operate even if the guest has firewall issues, broken networking, or is not yet joined to a domain. It is also useful in automated build or test environments where you want to configure VMs from the host scripts without exposing extra ports.