Migrate Azure VM from one subscription to another

If you need to migrate a VM from one Azure subscription to another subscription there is a quick way to do it using PowerShell. You can find the script in my GitHub repository.

At a high level these are the two steps we do:

  1. Create a copy of the boot disk directly from one subscription into another subscription
  2. Create a new VM in the target subscription using the newly created boot disk

Below is a more detailed description of all the sections in the script:

  1. Define the variables for the source and target subscription. Normally these are all the values that you need to modify.
  2. Calls Get-AzureRMDisk in the source subscription to get the information about the source disk
  3. Change context to the target subscription
  4. Calls New-AzureRmDiskConfig and New-AzureRmDisk to create a copy of the source disk. At this moment we have a copy of the disk in the target subscription. From this point, we follow the normal process to create a VM from an existing boot disk.
  5. Create a Virtual Network which includes a subnet, a Network Security Group and firewall rules
  6. Create a VM which includes a Public IP, a NIC connected to the Virtual Network and the boot disk created in step #4 above.

You can find a copy of the script here: [LINK]