Move VMs from & to anywhere in Azure

Automatically move VMs from anywhere & to anywhere in Azure:

  • Move VMs across subscriptions
  • Move VMs across tenants
  • In the same region or across regions
  • No downtime on the source VM (if there’s no data disks), the source VM remains in-tact
  • Copies both the OS disk and any data disks attached to the VM
  • Both Standard & Premium managed disks supported

2018-04-29_1212

Works with ARM Managed Disk based VMs only. This script is fully automatic and cleans up temp disks & storage accounts at the very end. It shows the copy process and doesn’t waste time by coping white space on disks (e.g. if you had a 1023GB disk and only 1GB was in use, the time it takes to copy 1GB of data). If you had multiple data disks attached to a VM, this script keeps a track of the disk LUN numbers, when you re-attach the disks at the end using the Azure portal, you simply attach the data disks in the order of the LUN number specified on the data disks.

2018-04-29_1326

Instructions:

  • Run the script
  • It prompts you for source & target credentials & subscriptions
  • prompts you to select a source VM from a list of managed disk based VMs
  • prompts you to select a target region from a list of Azure regions
  • prompts you to enter a target resource group
  • It will prompt you to shut down the source VM if there’s data disks, it can’t possibly copy all the disks in sync, the end state will be un-comprehensible.

This script sets up the target resource group along with exact copies of managed disks from the source VM. The script uses its own naming convention for the target disks as per the screenshot above (with the date tacked on the end). From there, you manually create the new VM using the Azure portal and attach the disks back to the VM and follow the process of creating a normal VM in the Azure portal.

In the Azure portal on the OS managed disk blade, choose the option to ‘Create VM‘ and and follow your nose to create a VM in the Azure portal, then attach any data disks in the order of LUN IDs specified in the data disk display names (starting at xero).

2018-04-29_1338

If you have issues with the script below (errors etc), check first the very top line and install the same PowerShell module that I wrote the script with.

3 Comments

  1. martin chamambo

    Good day , i was implementing your script and its throwing an error after copying some data as shown below

    Copying the Managed Disk…

    CopyId : 7c9c7632-c336-41e1-994c-d067860cff5f
    CompletionTime : 3/17/2019 9:22:38 AM +00:00
    Status : Failed
    Source : https://md-nckrg2gdpq2t.blob.core.windows.net/vt3wbbdw02kf/abcd?sv=2017-04-17&sr=b&si=ffdeac3e-5976-44fd-ad59-1edfdd791742&si
    g=ZYpAZpHPyL2XY9b4ybb%2BNbkUxwOKGhDHX6U3DOa8EhA%3D
    BytesCopied : 81612800000
    TotalBytes : 1098437886464
    StatusDescription : 403 AuthenticationFailed “Copy failed when reading the source.”
    DestinationSnapshotTime :

    New-AzDisk : Cannot import source blob https://46944050949490.blob.core.windows.net/vhds/Data_QlikSenseProd_Lun0_20190317.vhd since it has not been
    completely copied yet. Copy status of the blob is CopyFailed.
    ErrorCode: BadRequest
    ErrorMessage: Cannot import source blob https://46944050949490.blob.core.windows.net/vhds/Data_QlikSenseProd_Lun0_20190317.vhd since it has not been
    completely copied yet. Copy status of the blob is CopyFailed.
    ErrorTarget:
    StatusCode: 400
    ReasonPhrase: Bad Request
    OperationID : 49581a14-aeed-4e70-8247-8ea454e0c571
    At C:\Users\martin\Desktop\Untitled2.ps1:172 char:9
    + New-AzDisk -Disk $diskConfig -DiskName $ManagedDisk.TargetNam …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : CloseError: (:) [New-AzDisk], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Automation.NewAzureRmDisk

    AZURE_USERNAME_HERE Microsoft Azure 82a44e23-540a-4a9c-a1b7-13cb490e80c8 AzureCloud

    Name : 762a48b6-c0a4-44b6-860a-0f7799bbb925
    StartTime : 3/17/2019 11:23:04 AM
    EndTime : 3/17/2019 11:23:37 AM
    Status : Succeeded
    Error :

    AZURE_USERNAME_HERE Microsoft Azure 82a44e23-540a-4a9c-a1b7-13cb490e80c8 AzureCloud
    AZURE_USERNAME_HERE Microsoft Azure 82a44e23-540a-4a9c-a1b7-13cb490e80c8 AzureCloud
    AZURE_USERNAME_HERE Microsoft Azure 82a44e23-540a-4a9c-a1b7-13cb490e80c8 AzureCloud

    1. It’s the time it takes for the SAS URL to be alive for

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s