Tag: HVC

Hyper-V HVC SSH Direct for Linux VMs

HVC – SSH Direct for Linux VMs on Hyper-V

If you are running Hyper-V on Windows 10 or Windows Server 2016, you probably know about a feature called PowerShell Direct. I also mentioned that PowerShell Direct is one of the 10 hidden features in Hyper-V you should know about. PowerShell Direct lets you remotely connect to a Windows Virtual Machine running on a Hyper-V host, without any network connection inside the VM. PowerShell Direct uses the Hyper-V VMBus to connect inside the Virtual Machine. Of course, this feature is convenient if you need it for automation and configuration for Virtual Machines. As this is great for Windows virtual machines, it does not work with Virtual Machines running Linux. In the latest Windows 10, Windows Server 1803 (RS4) and Windows Server 2019 (RS5) Insider Preview builds, Microsoft enabled a tool called HVC. HVC is a tool which allows you to do some command line VM management. HVC SSH is basically PowerShell Direct for Linux VMs.

This allows connecting to a Linux VM using SSH over the Hyper-V VMBus. You are also able to copy files inside a virtual machine using scp, similar to Copy-item -ToSession using PowerShell Direct. You can read more about PowerShell Direct on my blog or the Microsoft Doc pages.

How to connect to Linux VMs using SSH Direct

HVC SSH on Hyper-V

To connect to Linux VMs using SSH Direct (HVC) type hvc.exe into the command line or PowerShell. This will give you all the possible command options. Of course, SSH has to big configured inside the Linux virtual machine.

hvc ssh Thomas@VMNAME

To make this work, the SSH server inside the VM needs to be configured.

Final Thoughts

A pretty cool tool which will be available in the official releases of Windows 10 and Windows Server 1803, released this spring. Later this year this feature will also be included in Windows Server 2019. If you want to try it out today, give the Windows Insider Preview builds a spin.

Thanks to Ben Armstrong for pointing this out ;)



PowerShell Direct Enter-PSSession

Hyper-V PowerShell Direct

One of the new features of Hyper-V in Windows Server 2016 and Windows 10 is called PowerShell Direct. PowerShell Direct lets you remotely connect to a Virtual Machine running on a Hyper-V host, without any network connection inside the Virtual Machine. PowerShell Direct uses the Hyper-V VMBus to connect inside the Virtual Machine. This feature is convenient if you need it for automation and configuration for Virtual Machines or if you for example messed up network configuration inside the virtual machine and you don’t have console access.

Right now, there are two ways to use PowerShell Direct:

  • Create and exit a PowerShell Direct session using PSSession cmdlets
  • Run script or command with the Invoke-Command cmdlet
  • Use the PowerShell Direct session to copy files using the copy-item cmdlet

Requirements:

  • The virtual machine must be running locally on the Hyper-V host and must be started.
  • You must be logged into the host computer as a Hyper-V administrator.
  • You must supply valid user credentials for the virtual machine.
  • The host operating system must run Windows 10, Windows Server 2016, or a higher version.
  • The virtual machine must run Windows 10, Windows Server 2016, or a higher version.

PowerShell Direct examples

You can open a new interactive PowerShell Direct Session:

PowerShell Direct Enter-PSSession

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

PowerShell Direct Invoke-Command

You can use Invoke-Command to send script blocks to your Hyper-V Virtual Machines.

Invoke-Command -VMName "VM01" -Credential (Get-Credential) -ScriptBlock { Get-Process }

You can also create a PowerShell Direct session and use the Copy-Item -ToSession cmdlet to copy files to or from the VM.

$s = New-PSSession -VMName "VM01" -Credential (Get-Credential)
Copy-Item C:\Files C:\Targetfiles -ToSession $s

Remember it, this is not the same as PowerShell Remoting, even if it uses the same cmdlets. With that, not everything is working using PowerShell Direct, for some scenarios, PowerShell Remoting works differently. If you want to do this with Linux virtual machines, there is a tool called hvc.exe, which allows you to do the same.

If you want to know more about PowerShell Direct, check out the Microsoft Docs pages.