Move Azure VM with Managed Disk to another Resource Group

At the moment of writing this blog it’s unfortunately not possible to move an Azure VM with Managed disk to another Resource Group or to another Description. However, Microsoft says on the Azure Portal that this will be possible in the near feature. For the time being, I have chosen to write a small PowerShell script that will do the move fully automated for you. At the moment the only way to move an Azure VM with Managed Disk to another resource group is redeploying the VM. To achieve this you need to perform the following steps (some from the portal and some from PowerShell) manually:

  1. Shutdown VM
  2. Collect the required information like Networking, VM size, Storage etc.
  3. Create a Snapshot
  4. Create or use an existing Azure Storage Account to copy the Snapshot to
  5. Remove the VM
  6. Create a new Azure VM in the new Resource Group with the collected information and Snapshot disk from the Azure Blob
  7. The Azure VM will start automatically, check if the VM functions as it should and remove the Snapshot and Azure Storage Account.

As you can see there are about 7 steps needed to move an Azure VM with a Managed Disk. The script that I have written will do all the steps automatically with only 3 variables that you need to define while running the script.

How the script works:

  1. When you run the script it will prompt you a login window, if you are not logged in Azure yet.
  2. If you have one subscription associated to your account, it will select that one as the default. If you have multiple subscriptions associated to your account, then a window will open so you can select the right subscription.
  3. At this step a window will open and will list all the Resource Groups in the selected subscription. Select here the Resource Group which contains the VM
  4. Now a new window will open so you can select the VM which exists in the selected Resource Group
  5. The final window will again list all the Resource Groups, now you should select the Resource Group where you want to move the VM to.

I recommend to test this in your test environment before using it in production. I hope this was helpful for you guys. May you have any feedback or suggestions, please let me know.

You can also the download the script from my GitHub

This Post Has One Comment

  1. Julien PERON

    Hello, Thanks for the script but it seems that a mistake is present
    On $storageAccountType = “StandardLRS” doesn’t exist
    Correct typo = “Standard_LRS”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.