No network connection needed with Virtual Machine Connection tool

The Virtual Machine Connection tool allows users to connect to the console of a virtual machine running on the Hyper-V server and has been available since the first version of Hyper-V. The tool supports the ability to perform a number of common tasks. Starting with Windows Server 2012 R2, it is now possible to redirect local resources to virtual machines and copy files to them without requiring a network connection.

Redirect local resources

Several local resources can be redirected when connecting to a virtual machine running on a Hyper-V 2012 R2 host, including display configuration, audio, printers, clipboard, local drives, maps chip, USB devices and plug and play (PnP). devices. Once enhanced session mode is enabled on the Hyper-V server and you connect to a virtual machine that supports local resource redirection, you can switch to the Local Resources tab. In this tab, you can select or deselect the resources you want to redirect with the Virtual Machine Connection tool. For example, you can select local drives, printers, and clipboard, as shown in Figure 1.

Figure 1

By default, enhanced session mode allows redirection of display, printers, and clipboard configuration. Printer redirection makes VM printing available to the local printer connected to the Hyper-V host, and clipboard redirection enables copy/paste functionality on the VM session.

A positive point of the enhanced session mode is that it is possible to redirect local drives and PnP devices, which are injected after the session is established. Just check the box “Records that I plug in later” setting for local drives and “Devices I plug in later” for other PnP devices as shown in the screenshot above. Whenever you inject a USB flash drive or connect a local drive to the Hyper-V host, session mode will ensure that the device is available to the current VM session without re-establishing the session. RemoteFX USB device redirection may not work due to a group policy that is not configured by default. You may want to enable the “Allow RDP redirection of other supported RemoteFX USB devices from the computer” in the virtual machine. The Group Policy Object, or GPO, policy is located under the “Computer ConfigurationAdministrative TemplatesWindows ComponentsRemote Desktop ServicesRemoteFX USB Device Redirection” node.

Display configuration redirection now supports full-screen mode for the virtual machine. All you need to do is move the slider in the display configuration until the value reaches “Full Screen” as shown in Figure 2.

There is no need to select or deselect the resources you want to redirect each time you connect to a virtual machine through the Virtual Machine Connection tool. Just check the “Save my settings for future connections for this virtual machine“, as shown in Figure 2.

Display Setup
Figure 2

The settings for the resources to redirect are saved in the folder called Users%UserName%AppDataRoamingMicrosoftWindowsHyper-VClient1.0. A file named “vmconnect.rdp.GUID of the VM.Config” is created for each VM. The next time you connect to the virtual machine using the virtual machine connection tool or click the “Connect” action from the Hyper-V manager, all the resources you have selected for redirection will be automatically available.

If you need to change session settings or local resources to redirect, you can do so by right-clicking the virtual machine in Hyper-V Manager and selecting “Edit Session Settings” as shown in figure 3.

Change session settings
picture 3

The next time you connect to the virtual machine from Hyper-V Manager, the virtual machine session will still be established when using enhanced session mode.

Copy files to a VM

In previous versions of Hyper-V, you had to shut down the virtual machine before you could copy the file to it. A traditional approach would be to shut down the VM, mount the VHD file using Windows Explorer, and then copy the file. Although enhanced session mode allows you to copy files using clipboard redirection, it is limited to the current VM session. If you need to copy a file to all VMs on a host, you can do so using the Copy-VMFile PowerShell cmdlet.

Hyper-V 2012 R2 Integration Services added a new service called Client services, which helps users copy files to virtual machines without a network connection. Before you can use the Copy-VMFile PowerShell cmdlet, make sure you have enabled guest services on the virtual machine’s properties page, as shown in Figure 4.

Client services
Figure 4

Besides enabling guest services on the virtual machine properties page, you also need to ensure that the Hyper-V Guest Service Interface service is running in the virtual machine.

You can also enable guest services for all or just one VM by running the following PowerShell commands:

To activate a specific VM:

  • Get-VM -Name VM1-Win812 | Enable-VMIntegrationService -Name “Guest Service Interface”

To enable for all VMs:

  • Get-VM | Enable-VMIntegrationService -Name “Guest Service Interface”

Once guest services are enabled, you can use the PowerShell Copy-VMFile cmdlet to copy files to any or all VMs using these commands:

To copy a file to a single VM:

  • Copy-VMFile “VM1-Win812” –SourcePath “D:LabFilesHowTo.DOCX” –DestinationPath “C:LAbFilesHowTo.DOCX” –CreateFullPath –FileSource host

This command copies a file from source D:LabFiles to a single virtual machine named “VM1-Win812”. If you need to copy a file to multiple VMs, use the –Name parameter with the command and specify the VM names, separated by commas, as shown in this command:

  • Copy-VMFile –Name VM1, VM2, VM3 –SourcePath “D:LabFilesHowTo.DOCX” –DestinationPath “C:LAbFilesHowTo.DOCX” –CreateFullPath –FileSource host

If the file already exists in the virtual machine, you can use the –Force switch with the command to overwrite the file, as shown in the command below:

  • Copy-VMFile –Name VM1, VM2, VM3 –SourcePath “D:LabFilesHowTo.DOCX” –DestinationPath “C:LAbFilesHowTo.DOCX” –CreateFullPath –FileSource host -Force

Hyper-V 2012 R2 brings many improvements and features. It becomes easy for virtual administrators, test developers, and users to redirect local resources and copy files to a virtual machine without requiring a network connection using enhanced session mode and guest services features.