Using PowerShell to copy files to guest virtual machines is pretty handy, but there is a prerequisite before you can do it.
Copying files directly to virtual machines is a handy feature of Hyper-V, and allows you to distribute files quickly to a large number of VMs. Here is an example of copying a file from the host hypervisor to a VM housed therein:
PS C:\MyDirectory> copy-vmfile "MyTestVM" -SourcePath "C:\Source\MyFile.zip" -DestinationPath "C:\target\MyFile.zip" -FileSource HOST
If you don’t have a standard method of deploying Hyper-V virtual machines, it’s very easy to forget to turn on integration services. If you forget, you’ll be met with big error, similar to this:
copy-vmfile : Failed to initiate copying files to the guest.
'MyTestVM' failed to initiate copying files to the guest: The device is not ready. (0x80070015). (Virtual machine ID 12345678-ABCD-1234-EFAB-1A2B3C4D5E6F)
At line:1 char:1
+ copy-vmfile "MyTestVM" -SourcePath "C:\source\MyFile ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-VMFile], VirtualizationException
+ FullyQualifiedErrorId : Unspecified,Microsoft.HyperV.PowerShell.Commands.CopyVMFile
Fortunately, the fix is easy. From an elevated PowerShell prompt, simply enter the following command for the troublesome VM:
Enable-VMIntegrationService -VMName MyTestVM -Name "Guest Service Interface"