July 8, 2018
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:
- Create a copy of the boot disk directly from one subscription into another subscription
- 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:
- Define the variables for the source and target subscription. Normally these are all the values that you need to modify.
- Calls Get-AzureRMDisk in the source subscription to get the information about the source disk
- Change context to the target subscription
- 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.
- Create a Virtual Network which includes a subnet, a Network Security Group and firewall rules
- 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]