How to clone Windows virtual machine on Azure

In this blog post we will learn how to clone a Windows virtual machine in Azure. It is important to know that there are two choices when it comes to cloning Azure VM:

  • You can generalize the existing VM using sysprep and create a new virtual machine from this image.
  • You can copy the existing OS disk image to a new storage account and create a new virtual machine with this disk.

Today we will cover the second option. Its upside is that you will get an exact copy of an existing VM. The downside is that you will need to copy a 130 GB disk image.

First of all, you will need Azure Powershell tools installed. You will also need to download and install AzCopy — a tool to copy Azure storage blobs. After you've done all that, just save the following script to your hard drive and run it in PowerShell:

The script will ask for various bits of information. The most important are an Uri for the source OS disk and storage account key. You can get both by navigating to your existing VM's storage account in Azure portal. First, open up a Keys pane and copy the Key1 value. Then open the Overview pane, select Blobs, click the vhds container and choose Properties. Now you can copy the container Uri.

Note that the process of copying the OS disk image can take a very long time as all the VMs are created with the fixed-size disks of 130 GB. After the script finishes, you can go to your Azure portal and play with your new virtual machine.