How to relocate Hyper-V VM files to another location

Either because your storage device begins to run out of space, or you simply need to reorganize the files of your virtual machines it is often necessary to move the storage of our virtual machines to a new location. In this post, I want to show you how you can use the Move-VMStorage cmdlet to perform Hyper-V storage migration.

move-vmstorage

Set the variables

Here, we define the name of the VM and the hyper-v hostname.

Move all the files of the VM

To move all the files of the virtual machine (smart paging file, snapshot files, VHDs, and configuration files) to the same location. Use the -DestinationStoragePath parameter. First, define the path where the files will be stored and then run the following PowerShell command as administrator.

Move only the configuration files of the VM

if you want to move only the configuration files of the virtual machine to another location. Use the -VirtualMachinePath parameter. Define the path where the files will be stored and then run the following PowerShell command as administrator.

Move VHD/VHDX files

To move a single virtual disk (VHD / VHDX). You must use the -vhds parameter. This parameter expects to receive a hash table that has two entries.

The first entry specifies the current location of the virtual hard disk to move, and has a SourceFilePath key:

The second entry specifies the new location for the virtual hard disk and has a DestinationFilePath key:

Important: The virtual hard disk name must be identical in both entries.

You must declare the hashtable as shown below and then use the Move-VMStorage cmdlet with the following syntax:

if you want to move several virtual disks and want to move them to different locations. You must define one or more hash tables within an array as shown below.

One last example

In the following example, I want to show you how to combine the use of various parameters, you can move the vhdx files and the VM configuration files to different locations.

Thanks for reading my post. I hope you find it useful.

If you want to know more about Move-VMStorage cmdlet, check out this link: https://docs.microsoft.com/en-us/powershell/module/hyper-v/move-vmstorage?view=win10-ps