Guest Services in Hyper-V and Copy-VMFile

Русская версия/Russian version

Windows Server 2012 R2 provides a lot of updates and improvements to Hyper-V. The most visible change is the new guest service “Hyper-V Guest Service Interface” or just “Guest Services”, which disabled ,by default in the properties of every VM on 2012 R2 Hyper-V.
copyvmfile_4
This service has a really modest functional, but extremely useful. Guest Services allows you to copy the necessary files between the host (server Hyper-V, on which are placed the target VMs = parent partition) and virtual machines (= child partition) without any load on the network components. The copying process is provided by link between Hyper-V host and VM through vmbus (Virtual Machine Bus).hv_arch
Also, the vmicguestinterface service (from the virtual machine side) responsible for functionality integration service components  on the guest OS level.   Altogether,  we  have got native feature for point-to-point (for example, host 1 VM in the DMZ) or multi-point (host VMs) copying necessary files between Hyper-V partitions

Before using this new feature you have to check:

1) Hyper-V Integration services must be up-to-date. Version has to be at least 6.3.9600.16384.

Get-VM | Select Name, IntegrationServicesVersion

2) Guest Services enabled for target VMs

#Gets current VM configuration
Get-VM|Get-VMIntegrationService|ft VmName,Name,Enabled -AutoSize
#Enabling Guest Service
Get-VM | Enable-VMIntegrationService -Name "Guest Service Interface"

copyvmfile_5
3) vmicguestinterface service must be running inside the guest OS

Get-Service vmicguestinterface

sss

Service management is provided by only one cmdlet  Copy-VMFile ((Microsoft.HyperV.PowerShell.GuestServiceInterfaceComponent) , which has a list of required parameters:

-SourcePath = what we want to copy (UNC is supported!)
-DestinationPath = where we want to save files
-FileSource = file source type
-VMName   = VM names

Example:

#Copies 2012R2.ISO file from file source HOST to VM with name Server 2012R2_1 and saves files to pre-created folder C:\ISO on guest OS
Copy-VMFile "Server2012R2_1" -SourcePath C:\ISO\2012R2.iso -DestinationPath C:\ISO\2012R2.iso -FileSource Host

If you don’t have pre-created destination path – you will get error. To automate process of creation necessary files you have to use -CreateFullPath  parameter that checks and creates folders, if they are not exist.

Copy-VMFile "Server2012R2_1" -SourcePath C:\ISO\2012R2.iso -DestinationPath C:\ISO\2012R2.iso -FileSource Host -CreateFullPath

Process of copying:

copyvmfile_1

Final result:copyvmfile_3

UNC:

copy_vm_file_unc