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:
- 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.
- 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:
- First, create a snapshot on the VM
- Then move the snapshot to a Storage account in the target area. Use the first script here.
- 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:
- Create a new VM using the image
- Create a snapshot on the VM
- Move the snapshot across to a Storage Account in the target area. Use the first script here.
- Create a VM using the snapshot in the target area using the second script.
- 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