Blog

Hyper-V does not have a built-in cloning feature for virtual machines (unlike VMware), except when using Virtual Machine Manager. To create a full copy of an existing VM, you can use the import and export functions. This article explains how to clone a virtual machine in Hyper-V using import/export via the Hyper-V Manager graphical interface, PowerShell, and Windows Admin Center (WAC).

You can purchase Windows Server from our catalog from 10.80 €

Download original Windows Server installer from our website.

Important Notes on Cloning Windows Virtual Machines

When cloning virtual machines with Windows, note that the cloned VM will have the same SID (Security Identifier). To reset the SID, use the sysprep utility. Before cloning a reference Windows image, run the following command:

%WINDIR%\system32\sysprep\sysprep.exe /generalize /shutdown /oobe

This will shut down the VM, and upon the next boot (for both the original and the clone), a new SID will be generated. It’s also not recommended to clone VMs that are joined to an Active Directory domain.

Exporting and Importing VMs via Hyper-V Manager

The first step is to export the virtual machine to a separate directory.

1. Launch Hyper-V Manager, select the VM you want to clone, and choose Export from the context menu.

Starting with Hyper-V in Windows Server 2012 R2, you can export running virtual machines without shutting them down.

2. Specify the directory where the VM should be exported.

3. The export status will be displayed in the Hyper-V Manager status bar.

Exporting a VM is often used as a simple method for creating Hyper-V backups.

4. You can also export a specific VM snapshot (checkpoint). Select the desired snapshot in the Checkpoints tree and choose Export.

Importing a VM

To import a virtual machine, click the host name in Hyper-V Manager and select Import Virtual Machine.

1. Specify the path to the directory containing the exported VM files.

2. During import, Hyper-V offers three options for registering the VM on the host:

Register the virtual machine in-place — register the VM using its existing unique ID.

Restore the virtual machine — copy the VM files to a new directory while retaining the original ID.

Copy the virtual machine — copy the VM to a new directory and generate a new ID.

3. To create a clone of the VM with a new ID, select the third option. Then, specify the directories for storing the VM files and virtual hard disks (VHDX).

4. Specify the directory for storing the VM’s VHDX virtual disks.

After this, the new cloned virtual machine will appear in the Hyper-V console.

Cloning VMs via Export/Import in Hyper-V with PowerShell

To export a VM in PowerShell, use the following command:

Export-VM -Name "win10" -Path 'C:\VHD\export'

To export a running VM, use the CaptureLiveState parameter, which specifies how to copy the VM’s memory state. Examples include:

CaptureSavedState – export the memory state (default);

CaptureDataConsistentState – export the VM state from a Production checkpoint;

CaptureCrashConsistentState – export without saving memory contents.

Export-VM -Name "win10" -Path 'C:\VHD\export' -CaptureLiveState CaptureCrashConsistentState

To export a specific VM snapshot, specify its name. First, list the snapshots for the specified VM:

Get-VMSnapshot -VMName win10

Then export the desired snapshot by its name:

Export-VMSnapshot -Name “win10 - (2/17/2021 - 9:52:20 PM) Standard” -VMName win10 -Path 'C:\VHD\export'

After the export is complete, you can import the VM. To register the VM in its current storage location, run:

Import-VM -Path "C:\VHD\export\win10\Virtual Machines\1117A061-0B50-4BC2-850C-88CCD4C114FB.vmcx"

To create a clone of the VM with a new ID, use the GenerateNewId parameter:

Import-VM -Path "C:\VHD\export\win10\Virtual Machines\1117A061-0B50-4BC2-850C-88CCD4C114FB.vmcx" -VhdDestinationPath "C:\VHD\win10_2" -VirtualMachinePath "C:\VHD\win10_2"

The VhdDestinationPath parameter specifies the directory for copying the VM’s VHDX files, and the VirtualMachinePath parameter specifies the directory for the VM’s configuration files. If these parameters are not specified, the VM files will be copied to the default directory configured in the Hyper-V host settings (C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\).

You can also specify directories for checkpoints (SnapshotFilePath) and the smart paging file (SmartPagingFilePath).

Note that the cloned VM appears in the Hyper-V console with the original name. To rename the new VM, first retrieve its ID:

get-vm | select VMNAME,VMId

You will see two VMs with the same name but different IDs. Rename the VM with the ID that differs from the imported VM’s ID. Copy the ID of the new VM and rename it:

get-vm | Where-Object {$_.VMId -eq "24ad8934-f650-46f6-9caa-2a3b79b79bd5"} | Rename-VM -NewName win10_2

Next, rename the virtual hard disk for convenience:

Get-VHD -VMId 24ad8934-f650-46f6-9caa-2a3b79b79bd5 | Select Path | Rename-Item -NewName win10_2.vhdx

Remove-VMHardDiskDrive -VMName win10_2 -ControllerType SCSI -ControllerLocation 0 -ControllerNumber 0

Add-VMHardDiskDrive -VMName win10_2 -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0 -Path "C:\VHD\win10_2\win10_2.vhdx"

Change the MAC address of the virtual network adapter (you can set a new static MAC or configure dynamic MAC address assignment):

Set-VMNetworkAdapter -VMName win10_2 -DynamicMacAddress

Start-VM -Name win10_2

Before connecting the new VM to the network, it’s advisable to rename it and assign a new IP address (if using DHCP, this step can be skipped). You can connect to the new VM via PowerShell Direct using the Invoke-Command or Enter-PSSession cmdlets:

Enter-PSSession -ComputerName win10_2 -Credential (Get-Credential)

Rename-Computer win10_2

Remove-NetIPAddress -InterfaceAlias “Ethernet” -AddressFamily IPV4

New-NetIPAddress -IPAddress 192.168.31.50 -InterfaceAlias “Ethernet” -AddressFamily IPv4 -PrefixLength 24

Restart-Computer

Cloning Virtual Machines in Hyper-V via Windows Admin Center

Cloning VMs in Hyper-V without intermediate export and import became possible in Windows Admin Center v2009.

1. Launch Windows Admin Center (WAC), navigate to the Virtual Machines section, select the desired VM, and click Manage -> Clone.

2. Specify the name of the new VM and the directory for storing its files.

The cloning wizard includes an option “I have already run sysprep on my VM”. If you haven’t generalized the image with Sysprep, Hyper-V will create a snapshot of the source VM, run Sysprep, and clone the VM into a new one.

For cloning VMs with guest operating systems other than Windows, always enable this option.

3. Wait for the cloning process to complete—the new VM will have a new unique ID.

Now you know how to clone Hyper-V virtual machines using Hyper-V Manager, PowerShell, and Windows Admin Center. These methods provide flexible management of your virtual infrastructure and enable rapid deployment of virtual machines across different hosts.

banner for Windows
Buy Windows от product key from
8.00 € Find Out More
Subscribe
Notify of
guest
0 comments
Inline Feedbacks
View all comments