Script Sample - VM Operations - Working with VM Snapshots and moving the Managed VMs across subscriptions and regions

@20aman    Dec 14, 2018

This script sample is a combination of two scripts. At the time of the writing of this blog, the feature to move managed disks or images built using Managed disk VMs is not available in Azure. A workaround for this is as follows.

The two scripts

The two scripts provided are:

  1. Copy-SnapshotToStorage.ps1 - This copies the Snapshot to a Storage account. This storage account can be in different subscription or even different region. The script uses the "Start-AzureStorageBlobCopy" cmdlet and also shows the progress of the copy operation.
  2. Create-VMFromSnapshot.ps1 - This creates a VM from a Snapshot in a Storage account. It creates a Managed Disks VM leveraging the snapshot.

Scenario 1 - Moving a Managed VM or a Disk across subscriptions or regions

You will need to follow the below steps to move a VM built using Managed disks across subscriptions or regions:

  1. First, create a snapshot on the VM
  2. Then move the snapshot to a Storage account in the target area. Use the first script here.
  3. Then create a VM using the snapshot by leveraging the second script provided in this post.

Scenario 2 - Moving the Image across subscriptions or regions

You will need to follow the below steps to move an Image built using Managed disks across subscriptions or regions:

  1. Create a new VM using the image
  2. Create a snapshot on the VM
  3. Move the snapshot across to a Storage Account in the target area. Use the first script here.
  4. Create a VM using the snapshot in the target area using the second script.
  5. Finally, capture the VM to an image. Delete the image and snapshots from both source and target once image is created in the target area.

Location of the Script

You can find this script in GitHub at this location: Working with Azure VM Snapshots





Comments powered by Disqus