none
Moving VM on Hyperv 2012 R2 server?

    Question

  • Hi,

    I restored a server VM the other day using Altaro VM backup and it was restored on to the host as:

    e:\Virtual machines\SRV-VM-Clone-2017-04-07 01-02 instead of e:\Virtual machines\SRV-VM. 

    Now the virtual hard disks reside under e:\Virtual machines\SRV-VM-Clone-2017-04-07 01-02

    and the VM is located at e:\Virtual machines\SRV-VM-Clone-2017-04-07 01-02\Virtual Machines

    This is because the old corrupted VM folder e:\Virtual machines\SRV-VM was still there.

    I removed the old corrupted (we were hit by ransomware)  VM through hyperv manager.

    Now I would like to rename the above new path to e:\Virtual machines\SRV-VM and the virtual machines path to 

    e:\Virtual machines\SRV-VM\Virtual Machines to keep consistency with the other VMs naming convention.

    This is a single host non clustered.

    I did a bit of googling and found out that I can use the powershell command called Move-VMStorage.

    I understand that this allows you to move the storage (ie the vhd, vhdx) to another location on the same host, but I cannot figure out how to rename/move the VM path in one composite command, the syntax is a little confusing.

    The command gives you options to rename the VM path as well.

    I know there is a way to fiddle with symbolic links as well as exporting/importing, but I want to avoid this avenue.

    Can someone give me a little help here?

    Thank you

    Best Regards

    Alfred56




    • Edited by alfred56 Wednesday, April 12, 2017 1:52 AM
    Tuesday, April 11, 2017 11:52 PM

Answers


  • Thank you for your very useful reply, but does this command also move the virtual machine itself, ie the vm guid xml file?

    Thank you.

    Yes. From the Technet link:

    -VirtualMachinePath

    Specifies the path to the virtual machine configuration file and associated memory files.

    OR if you just want to move everything for the VM into a single folder:

    -DestinationStoragePath

    Specifies a destination storage path to which all virtual machine storage is to be moved.


    • Edited by D.Pope MCSE Saturday, April 15, 2017 12:10 PM
    • Marked as answer by alfred56 Saturday, April 15, 2017 1:02 PM
    Saturday, April 15, 2017 12:09 PM

All replies

  • Renaming is a bit more complicated.  The easiest way to accomplish this is to create the directory structure you want, copy the VHD where you want it, and create a new VM on the host that points to the copied VHD.  The name and location of files is captured in the VM's configuration file.  While there are hacks to edit the configuration file, it is not supported and it not for the faint of heart.  It is much easier to simply create a new VM using the naming conventions you want.

    tim

    Wednesday, April 12, 2017 1:38 PM
  • Assuming you have enough space, just use the GUI Hyper-V manager to move the VM to the new location. Just right click on the VM, select Move... and follow the wizard and you can relocate all the VMs files to the folder(s) of your choosing.
    • Proposed as answer by D.Pope MCSE Friday, April 14, 2017 8:25 PM
    Thursday, April 13, 2017 1:22 AM
  • Assuming you have enough space, just use the GUI Hyper-V manager to move the VM to the new location. Just right click on the VM, select Move... and follow the wizard and you can relocate all the VMs files to the folder(s) of your choosing.

    Hi there,

    Thank you for your reply.

    I knew about moving the vm with hyperv manager, but I wanted to learn more on how to use the powershell command "Move-VMStorage". Sometimes you may not have hyperv manager installed and if you are trying to move the vm remotely on the host, powershell gives your more power.

    Saturday, April 15, 2017 3:32 AM
  • Hi there,

    Thank you for your reply.

    I knew about moving the vm with hyperv manager, but I wanted to learn more on how to use the powershell command "Move-VMStorage". Sometimes you may not have hyperv manager installed and if you are trying to move the vm remotely on the host, powershell gives your more power.

    https://technet.microsoft.com/en-us/itpro/powershell/windows/hyper-v/move-vmstorage

    Here's an example of exactly you're wanting to do...

    Example 2

    PS C:\> Move-VMStorage "Test VM" -VirtualMachinePath D:\TestVM\Config -SnapshotFilePath D:\TestVM\Snapshots -SmartPagingFilePath D:\TestVM\SmartPaging -VHDs @(@{"SourceFilePath" = "C:\TestVM\Disk1.VHDX"; "DestinationFilePath" = "D:\TestVM\Disks\Disk1.VHDX"}, @{"SourceFilePath" = "C:\TestVM\Disk2.VHDX"; "DestinationFilePath" = "D:\TestVM\Disks\Disk2.VHDX"})


    • Edited by D.Pope MCSE Saturday, April 15, 2017 3:38 AM
    Saturday, April 15, 2017 3:37 AM
  • Hi there,

    Thank you for your reply.

    I knew about moving the vm with hyperv manager, but I wanted to learn more on how to use the powershell command "Move-VMStorage". Sometimes you may not have hyperv manager installed and if you are trying to move the vm remotely on the host, powershell gives your more power.

    https://technet.microsoft.com/en-us/itpro/powershell/windows/hyper-v/move-vmstorage

    Here's an example of exactly you're wanting to do...

    Example 2

    PS C:\> Move-VMStorage "Test VM" -VirtualMachinePath D:\TestVM\Config -SnapshotFilePath D:\TestVM\Snapshots -SmartPagingFilePath D:\TestVM\SmartPaging -VHDs @(@{"SourceFilePath" = "C:\TestVM\Disk1.VHDX"; "DestinationFilePath" = "D:\TestVM\Disks\Disk1.VHDX"}, @{"SourceFilePath" = "C:\TestVM\Disk2.VHDX"; "DestinationFilePath" = "D:\TestVM\Disks\Disk2.VHDX"})


    Thank you for your very useful reply, but does this command also move the virtual machine itself, ie the vm guid xml file?

    Thank you.

    Saturday, April 15, 2017 11:46 AM

  • Thank you for your very useful reply, but does this command also move the virtual machine itself, ie the vm guid xml file?

    Thank you.

    Yes. From the Technet link:

    -VirtualMachinePath

    Specifies the path to the virtual machine configuration file and associated memory files.

    OR if you just want to move everything for the VM into a single folder:

    -DestinationStoragePath

    Specifies a destination storage path to which all virtual machine storage is to be moved.


    • Edited by D.Pope MCSE Saturday, April 15, 2017 12:10 PM
    • Marked as answer by alfred56 Saturday, April 15, 2017 1:02 PM
    Saturday, April 15, 2017 12:09 PM

  • Thank you for your very useful reply, but does this command also move the virtual machine itself, ie the vm guid xml file?

    Thank you.

    Yes. From the Technet link:

    -VirtualMachinePath

    Specifies the path to the virtual machine configuration file and associated memory files.

    OR if you just want to move everything for the VM into a single folder:

    -DestinationStoragePath

    Specifies a destination storage path to which all virtual machine storage is to be moved.


    Thank you very much. 

    Happy Easter to you and your family.

    Saturday, April 15, 2017 1:03 PM