By Crystal / Last Updated May 18, 2022

 

Hi All,

What is the easiest way to copy a file into a Hyper-V VM from its host?

- Question from Quora

How to copy file to Hyper-V virtual machine

Hyper-V virtual machine is running in an isolated environment that is independent of physical machine. So, if you want to copy files from VM to local machine or from Hyper-V host to VM, how do you perform it in the completely separate environment?

Next, I will introduce 4 ways to share files to Hyper-V VM. If you want to auto copy files to VMs periodically, or have several physical machines and VMs that you want to share files between, there is also a professional solution to try.

Quick Navigation:

4 Ways to copy or share files to Hyper-V VM

Here are 4 effective ways to transfer files between host and VM. If you are transferring non-system files and only want to make a one-time copy, then try any of the methods below.

Method 1. Create a Hyper-V shard network folder

In this way, you can share files between host and VM via network share.

1. Create a folder in the Hyper-V host and put the files into this folder.

2. Right-click the folder, then select Properties >> Sharing >> Share. Add Everyone and change the Permission Level as Read/Write.

create shared folder

3. Click Share. Review the folder and copy the link of it. Select Done.

You have created a shared folder in the local machine. Then you should access to your Hyper-V to add the network location into virtual machine.

4. Open a Hyper-V virtual machine, open This PC, select Add a network location to this VM, and paste the path of the shared folder into the box, and click Finish.

add network location

Now you can transfer the files between the Hyper-V host and guest easily.

Method 2. Use Hyper-V PowerShell cmdlet to copy files

Before you start sharing files to virtual machine, please enable the Guest Services under Hyper-V Manager Integration Services.

enable guest service

You can copy the files from the host (source) to the guest Hyper-V virtual machine (destination) using this Copy-VMFile command.

PS C:\> Copy-VMFile "VMName" -SourcePath "F:\Test.txt" -DestinationPath "C:\Temp\Test.txt" -CreateFullPath -FileSource Host

Tip: The CreateFullPath parameter ensures creation of the destination folder inside the guest operating system if it doesn't exist.

If you need to copy a large number of files to a Hyper-V virtual machine, this method may not be very practical since the command will be error-prone and complicated for management.

Method 3. Mount the virtual hard disk to the host machine

1. Shut down the virtual machine first, then go to mount the VHD to the Hyper-V host.

2. Locate the path of virtual disk file and right-click it, then select Mount. It will map the VHDX file as a local disk drive.

3. Copy the files to the virtual hard disk as you want. When completed, right-click the mounted disk drive and select Eject to dismount the VHD.

You can power on the virtual machine and access to the copied files in Hyper-V VM.

Method 4. Use enhanced session mode to copy files from host to VM

This method is simple to copy and redirect local devices and resources to guest VMs, and it allows a VM connection tool to connect to VMs using Remote Desktop Protocol (RDP). This feature doesn’t require network connection between Hyper-V host and guest VM and could be used in Windows Server 2022, Windows Server 2019, Windows 10, Windows 8.1, Windows Server 2016, Windows Server 2012 R2.

1. Enable Enhanced Session Mode Policy in Hyper-V Settings.

enable enhanced session mode

2. Right-click a VM and select Connect.

3. Select Show Options >> Local Resources >> More. Then select the drive that you want to use on the Hyper-V VM, and click Ok.

select drive

4. Back to the Display page, select Save my settings for future connections to this virtual machine. Then click Connect.

5. Access to This PC and locate to Redirected drives and folders to copy files to Hyper-V VM as you need.

Use backup software to auto copy files to Hyper-V VM easily

Beside the 4 ways to copy Hyper-V host files to virtual machine, you can also use backup tool to restore the copied files to any VM easily. For some enterprises who need to run large amounts of workloads, data security is also important for business. A professional software can safeguard the data and simplify the copying procedures.

Now, I will give you an example to copy files to virtual machine with AOMEI Centralized Backupper. It can centrally manage backup & restore and synchronization task for multiple Windows physical and virtual machines on the network. For example, you can:

  • Auto copy (changed) files from host to VM in real time, or vice versa
  • Create a task to backup multiple VMs (computers) at once
  • Create a system image from physical machine and restore it to VM, etc.

You can download and install ACB on the host computer as the central console, and install the Agent package on all client computers & VMs. Then you can centrally create File Backup, Partition Backup, System Backup, SQL Server Backup, or sync task for all of them.

Download the 30-day free trial to try it out:

Download Free Trial Win Servers & PCs
Secure Download

*To manage a VM, you need to assign a static IP to it before installing the Agent. Then you can launch ACB and Request Control over all the network connected computers (VMs).

How to copy files from Hyper-V host to VM in real time:

1. Open the Hyper-V VM, use the steps in Method 1 to create a share folder on it (to receive the copied files).

2. Launch the backup tool, click Tasks >> New Task >> Real-Time Sync.

>>To auto copy files with a specific schedule, choose Basic Sync and then set up a schedule.

>>To create a system/disk image and restore it to the VM, choose System Backup or Disk Backup accordingly.

Real Time Sync

3. Click Add Computers to specify the comptuer to copy files from, then you can select files/folders path you want to sync manually or based on certain rules.

Add Computer

4. On step 3, select storage. Enter the path of the network share you created on the target VM and click OK.

Add Storage

5. Then you can click Start Sync to create and execute the task. Similarly, you can copy files from Hyper-VM to host, or VM to VM.

✎Useful Tips

✦If you want to auto copy files to Hyper-V VM at a certain frequency, you can perform Basic Sync, and set up the schedule and scheme as you like:

On Schedule Settings page, set up backup frequency as you want.

On Backup Scheme Settings page, it provides you with 5 strategies to set up retention policy.

backup scheme

✦As an centralized backup software, it enables you to create a system/disk backup and restore it to another client computer (VM). This way you can also perform P2V or V2V easily. To resolve compatibility issues between different hardware, this's also a Universal Restore option.

System Restore Summary

Summary

This article introduces the convenient methods of Hyper-V copy files to VM. If you plan to transfer large amounts of host files in your production environment, trying this professional backup software is more economical and efficient.

Besides file backup, you can also perform disk backup to convert physical to VM in Hyper-V.