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


5 thoughts on “Guest Services in Hyper-V and Copy-VMFile”

  1. Hi mate,

    what did you do to get the source as UNC work?
    I got exceptions:
    Copy-VMFile : ‘VMName’ failed to copy file. (Virtual machine ID 39C130C0-51AD-4A7A-A9DE-347AA7BF71BC)
    ‘VMName’ failed to copy files to the guest: General access denied error (0x80070005). (Virtual machine ID 39C130C0-51AD-4A7A-A9DE-347AA7BF71BC)
    ‘VMName’ failed to copy the source file ‘\\sharepath\tmp\kb3069115_WorkerInstaller_x64.msp’ to the destination ‘D:\tmp\kb3069115_WorkerInstaller_x64.msp’ in the
    guest: General access denied error (0x80070005). (Virtual machine ID 39C130C0-51AD-4A7A-A9DE-347AA7BF71BC)
    You do not have permission to perform the operation. Contact your administrator if you believe you should have permission to perform this operation.
    At line:1 char:1
    + Copy-VMFile -ComputerName $VM.VMHost -Name VMName -SourcePath …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : PermissionDenied: (Microsoft.Hyper…FileToGuestTask:VMCopyFileToGuestTask) [Copy-VMFile], VirtualizationOperationFailedException
    + FullyQualifiedErrorId : AccessDenied,Microsoft.HyperV.PowerShell.Commands.CopyVMFileCommand

    I set the source UNC path permission as Everyone has Full permission for both Share permission and NTFS permission. It’s still throwing this error.

    Can you please give me some advice?

    Thanks
    River

    1. Looks like it only works when you run the command directly from host, but not working if you run it from other server by using Copy-VMFile -ComputerName or Invoke-Command -ComputerName etc…

      1. Hi, River Yang!
        Have you solved your issue? What type of error are you receiving after Copy-VMFile -ComputerName or ICM?

        I guess there is the only 1 right way to copy file to VMs -only from the original host or just use Copy-VmFile GUI if you want to copy multiple files (https://copyvmfilegui.codeplex.com) + both ways should work with -ComputerName parameter as well.
        That’s by design (but I have not check your scenario yet). + as I know, there are a lot limitations and “bugs” when you use ICM (especially, as a part of scripts in VMM or etc).

  2. I get the same sort of error if I try to use COPY-VMFILE and specify a -VMName and the -COMPUTERNAME of a VM on another node in our failover cluster.

    “You do not have permission to perform the operation”

Leave a comment