Exploring the Hyper-V 2012 R2 and Copy-VMFile Powershell cmdlet
Today I have been exploring a bit in the Windows 2012 R2 Preview and when looking in the technet article “What´s new in Hyper-V 2012 R2” I found the interesting part with the new Integration Service “Guest Services” that allows moving files from the host to the virtual machine without any network connectivity.
This requires two things, first that the “Guest Services” integration component is activated in the VM settings and also that the virtual machine has the latest integrational components installed and the “Hyper-V Guest Interface” service running.
When creating a new virtual machine this is not enabled but I have noticed that when you install Windows 2012 R2 inside the Virtual Machine it gets enabled somehow during the installation, both good and bad… Maybe you want to have some control on what VM´s get this enabled, this can however be a Preview “bug” and will change when the R2 is RTM.
Inside the VM the following Service is running and makes it possible to move files to the VM from the Host. Note that even that you can run the powershell cmdlet from a remote server that have the Hyper-V RSAT tools installed you will have to put the file/files you want to transfer to the VM on the host!
And with this command I move a file into the VM, the parameter -FileSource that only accepts Host today implies that it might be possible to also move files from the VM to the host in a later version. (this can be done with the mounting of the parent disk of a vhd/vhdx after a snapshot that I have done a blog post about before)
Move-Item c:\temp\vNiklasMove.txt -Destination \\hvr2\c$\temp\vNiklasMove.txt Copy-VMFile -VMName Yellow -ComputerName hvr2 -SourcePath C:\temp\vNiklasMove.txt -DestinationPath c:\temp\vNiklasMove.txt -FileSource Host -CreateFullPath
With the parameter -CreateFullPath the folders will be created that I have in the -DestinationPath inside the VM.
If you want to check what VM´s have this Integration guest service enabled you can check it with PowerShell and also disable it and only enable on a per VM basis when transferring files.
Get-VM -ComputerName hvr2 | Get-VMIntegrationService -Name "Guest Service Interface" | where Enabled -eq $true | Disable-VMIntegrationService -Passthru
And on the following screendump you can see that after disabling this I cannot transfer files to the VM.