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:
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.
After clicking OK, Azure will validate that what you are doing will work. After that it will start moving them:
Oh, and you can only perform one move job at a time, on both source and destination resource groups:
Audit Logs doesn’t contain much information about the job, but there is an event to look for in case you need it:
Little by little, you should see your resources appear in the new resource group:
And finally we’re done:
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:
$oldRg = "Cloudpuzzles-Mgmt" $newRg = "Cloudpuzzles-Move" $resourceName = "puzzlesha01" $resource = Get-AzureRmResource -ResourceName $resourceName -ResourceGroupName $oldRg Move-AzureRmResource -DestinationResourceGroupName $newRg -ResourceId $resource.ResourceId -Verbose
This will have you confirm that you really want to do this, and then start moving it:
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:
$oldRg = "Cloudpuzzles-Move" $newRg = "Cloudpuzzles-Mgmt" $resources = Find-AzureRmResource -ResourceGroupNameContains $oldRg Move-AzureRmResource -DestinationResourceGroupName $newRg -ResourceId $resources.ResourceId -Verbose
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:
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.