Move Azure VMs, networks and storage between Resource Groups

A nice new addition to Azure Resource Manager, is the ability to move Azure VMs, vnets and Storage Accounts between Resource Groups. We’ve had the ability to move resources for a long time, but only recently for the above resources. It’s important to note, that while you can move your virtual network, you cannot move Virtual Network Gateway, Local Network Gateways, and Connections – all of which are used when doing Site-to-Site VPN.

To move a resource through the portal, browse to your Resource Group, and in the top select Move:

moveresource1

On the next blade, we have to select which resources we want to move. You also have to select which resource group you want to move them to – you can choose an existing or create a new group. Finally you have to acknowledge that if you have tools or scripts to manage these resources, you will need to update those, after moving the resources.

moveresource2

After clicking OK, Azure will validate that what you are doing will work. After that it will start moving them:

moveresource3

Oh, and you can only perform one move job at a time, on both source and destination resource groups:

moveresource4

Audit Logs doesn’t contain much information about the job, but there is an event to look for in case you need it:

moveresource5

Little by little, you should see your resources appear in the new resource group:

moveresource6

And finally we’re done:

moveresource8

Of course this can also be done through PowerShell. The AzureRm.Resources module have a cmdlet for this: Move-AzureRmResource. To use this, we need to know the ResourceId property of the resource we want to move. The easiest way to do this, is to use Get-AzureRmResource and extract it from there. Example:

[powershell]$oldRg = "Cloudpuzzles-Mgmt"
$newRg = "Cloudpuzzles-Move"
$resourceName = "puzzlesha01"
$resource = Get-AzureRmResource -ResourceName $resourceName -ResourceGroupName $oldRg
Move-AzureRmResource -DestinationResourceGroupName $newRg -ResourceId $resource.ResourceId -Verbose[/powershell]

 This will have you confirm that you really want to do this, and then start moving it:

moveresource9

moveresource10

In case you want to move multiple resources at once, you just have to add those resource IDs to the line, like: $resource1.ResourceId,$resource2.ResourceId. If you want to move everything within a resource group, you can use the following cmdlets:

[powershell]$oldRg = "Cloudpuzzles-Move"
$newRg = "Cloudpuzzles-Mgmt"
$resources = Find-AzureRmResource -ResourceGroupNameContains $oldRg
Move-AzureRmResource -DestinationResourceGroupName $newRg -ResourceId $resources.ResourceId -Verbose[/powershell]

If you have extensions installed on your VMs, you will need to uninstall those first. If you don’t, you might end up with the following error:

Move-AzureRmResource : MultipleErrorsOccurred : Multiple error occurred: BadRequest,BadRequest. Please see details.
At line:1 char:1
+ Move-AzureRmResource -DestinationResourceGroupName $newRg -ResourceId …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Move-AzureRmResource], ErrorResponseMessageException
+ FullyQualifiedErrorId : MultipleErrorsOccurred,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.MoveAzureResourceCommand

The audit logs show the same error:

moveresource11

Thanks to the Azure Resource Manager team for clarifying the extension part! They’re working on surfacing errors like this for PowerShell and CLI tools.

3 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Facebook photo

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

Connecting to %s