Move resources to new resource group or subscription

This topic shows how to move resources from one resource group to another resource group. You can also move resources to a new subscription. You may need to move resources when you decide that:

  1. For billing purposes, a resource needs to live in a different subscription.
  2. A resource no longer shares the same lifecycle as the resources it was previously grouped with. You want to move it to a new resource group so you can manage that resource separately from the other resources.
  3. A resource now shares the same lifecycle as other resources in a different resource group. You want to move it to the resource group with the other resources so you can manage them together.

There are some important considerations when moving a resource:

  1. You cannot change the location of the resource. Moving a resource only moves it to a new resource group. The new resource group may have a different location, but that does not change the location of the resource.
  2. The destination resource group should contain only resources that share the same application lifecycle as the resources you are moving.
  3. If you are using Azure PowerShell or Azure CLI, make sure you are using the latest version. To update your version, run the Microsoft Web Platform Installer and check if a new version is available. For more information, see How to install and configure Azure PowerShell and Install the Azure CLI.
  4. The move operation can take a while to complete and during that time your prompt will wait until the operation has completed.
  5. When moving resources, both the source group and the target group are locked for the duration of the operation. Write and delete operations are blocked on the groups until the move completes.

Supported services

Not all services currently support the ability to move resources.

For now, the services that support moving to both a new resource group and subscription are:

  • API Management
  • Automation
  • Batch
  • Data Factory
  • DocumentDB
  • HDInsight clusters
  • Key Vault
  • Logic Apps
  • Mobile Engagement
  • Notification Hubs
  • Operational Insights
  • Redis Cache
  • Search
  • SQL Database server (Moving a server also moves all of its databases. Databases cannot be moved separately from the server.)
  • Web Apps (some limitations apply)

The services that support moving to a new resource group but not a new subscription are:

  • Virtual Machines (classic)
  • Storage (classic)
  • Virtual Networks
  • Cloud Services

The services that currently do not support moving a resource are:

  • Virtual Machines
  • Storage
  • Express Route

When working with web apps, you cannot move only an App Service plan. To move web apps, your options are:

  • Move all of the resources from one resource group to a different resource group, if the destination resource group does not already have Microsoft.Web resources.
  • Move the web apps to a different resource group, but keep the App Service plan in the original resource group.

You cannot move a SQL database separately from its server. The database and server must reside in the same resource group. When you move a SQL server, all of its databases are also moved.

Using PowerShell to move resources

Azure PowerShell is currently available in two releases - 1.0 and 0.9.8. If you have existing scripts and do not want to change them right now, you can continue using the 0.9.8 release. When using the 1.0 release, you should carefully test your scripts in pre-production environments before using them in production to avoid unexpected impacts.

1.0 cmdlets follow the naming pattern {verb}-AzureRm{noun}; whereas, the 0.9.8 names do not include Rm (for example, New-AzureRmResourceGroup instead of New-AzureResourceGroup). When using Azure PowerShell 0.9.8, you must first enable the Resource Manager mode by running the Switch-AzureMode AzureResourceManager command. This command is not necessary in 1.0.

New features will be added to only the 1.0 release. For information about the 1.0 release, including how to install and uninstall the release, see Azure PowerShell 1.0.

To move existing resources to another resource group or subscription, use the Move-AzureRmResource command.

The first example shows how to move one resource to a new resource group.

Copy
PS C:\> $resource = Get-AzureRmResource -ResourceName ExampleApp -ResourceGroupName OldRG
PS C:\> Move-AzureRmResource -DestinationResourceGroupName NewRG -ResourceId $resource.ResourceId

The second example shows how to move multiple resources to a new resource group.

Copy
PS C:\> $webapp = Get-AzureRmResource -ResourceGroupName OldRG -ResourceName ExampleSite
PS C:\> $plan = Get-AzureRmResource -ResourceGroupName OldRG -ResourceName ExamplePlan
PS C:\> Move-AzureRmResource -DestinationResourceGroupName NewRG -ResourceId ($webapp.ResourceId, $plan.ResourceId)

To move to a new subscription, include a value for the DestinationSubscriptionId parameter.

Using Azure CLI to move resources

To move existing resources to another resource group or subscription, use the azure resource move command. The following example shows how to move a Redis Cache to a new resource group. In the -i parameter, provide a comma-separated list of the resource id's to move.

Copy
azure resource move -i "/subscriptions/{guid}/resourceGroups/OldRG/providers/Microsoft.Cache/Redis/examplecache" -d "NewRG"
info:    Executing command resource move
Move selected resources in OldRG to NewRG? [y/n] y
+ Moving selected resources to NewRG
info:    resource move command OK

Using REST API to move resources

To move existing resources to another resource group or subscription, run:

Copy
POST https://management.azure.com/subscriptions/{source-subscription-id}/resourcegroups/{source-resource-group-name}/moveResources?api-version={api-version} 

In the request body, you specify the target resource group and the resources to move. For more information about the move REST operation, see Move resources.

Next steps