Skip to content

Commit 8d9f748

Browse files
committed
update
1 parent ac7b079 commit 8d9f748

File tree

1 file changed

+113
-109
lines changed

1 file changed

+113
-109
lines changed

articles/azure-resource-manager/management/move-resource-group-and-subscription.md

Lines changed: 113 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Move resources to a new subscription or resource group
33
description: Describes how to move resources to a new resource group or subscription, and the steps to take to ensure a successful move operation.
44
ms.topic: conceptual
5-
ms.date: 01/06/2025
5+
ms.date: 01/07/2025
66
ms.custom: devx-track-azurecli, devx-track-azurepowershell, devx-track-arm-template, devx-track-python
77
content_well_notification:
88
- AI-contribution
@@ -36,85 +36,93 @@ There are some important steps to do before moving a resource. By verifying thes
3636

3737
1. The source and destination subscriptions must exist within the same [Microsoft Entra tenant](../../active-directory/develop/quickstart-create-new-tenant.md). To check that both subscriptions have the same tenant ID, use Azure PowerShell or Azure CLI.
3838

39-
For Azure PowerShell, use:
39+
# [CLI](#tab/CLI)
40+
41+
```azurecli-interactive
42+
az account show --subscription <your-source-subscription> --query tenantId
43+
az account show --subscription <your-destination-subscription> --query tenantId
44+
```
45+
46+
# [PowerShell](#tab/PowerShell)
47+
48+
```azurepowershell-interactive
49+
(Get-AzSubscription -SubscriptionName <your-source-subscription>).TenantId
50+
(Get-AzSubscription -SubscriptionName <your-destination-subscription>).TenantId
51+
```
4052

41-
```azurepowershell-interactive
42-
(Get-AzSubscription -SubscriptionName <your-source-subscription>).TenantId
43-
(Get-AzSubscription -SubscriptionName <your-destination-subscription>).TenantId
44-
```
53+
---
4554

46-
For Azure CLI, use:
55+
If the tenant IDs for the source and destination subscriptions aren't the same, use the following methods to reconcile the tenant IDs:
4756

48-
```azurecli-interactive
49-
az account show --subscription <your-source-subscription> --query tenantId
50-
az account show --subscription <your-destination-subscription> --query tenantId
51-
```
52-
53-
If the tenant IDs for the source and destination subscriptions aren't the same, use the following methods to reconcile the tenant IDs:
54-
55-
* [Transfer ownership of an Azure subscription to another account](../../cost-management-billing/manage/billing-subscription-transfer.md)
56-
* [How to associate or add an Azure subscription to Microsoft Entra ID](../../active-directory/fundamentals/active-directory-how-subscriptions-associated-directory.md)
57+
* [Transfer ownership of an Azure subscription to another account](../../cost-management-billing/manage/billing-subscription-transfer.md)
58+
* [How to associate or add an Azure subscription to Microsoft Entra ID](../../active-directory/fundamentals/active-directory-how-subscriptions-associated-directory.md)
5759

5860
1. If you're attempting to move resources to or from a Cloud Solution Provider (CSP) partner, see [Transfer Azure subscriptions between subscribers and CSPs](../../cost-management-billing/manage/transfer-subscriptions-subscribers-csp.yml).
5961

6062
1. The resources you want to move must support the move operation. For a list of which resources support move, see [Move operation support for resources](move-support-resources.md).
6163

6264
1. Some services have specific limitations or requirements when moving resources. If you're moving any of the following services, check that guidance before moving.
6365

64-
* If you're using Azure Stack Hub, you can't move resources between groups.
65-
* [App Services move guidance](./move-limitations/app-service-move-limitations.md)
66-
* [Azure DevOps Services move guidance](/azure/devops/organizations/billing/change-azure-subscription?toc=/azure/azure-resource-manager/toc.json)
67-
* [Classic deployment model move guidance](./move-limitations/classic-model-move-limitations.md) - Classic Compute, Classic Storage, Classic Virtual Networks, and Cloud Services
68-
* [Cloud Services (extended support) move guidance](./move-limitations/classic-model-move-limitations.md)
69-
* [Networking move guidance](./move-limitations/networking-move-limitations.md)
70-
* [Recovery Services move guidance](../../backup/backup-azure-move-recovery-services-vault.md?toc=/azure/azure-resource-manager/toc.json)
71-
* [Virtual Machines move guidance](./move-limitations/virtual-machines-move-limitations.md)
72-
* To move an Azure subscription to a new management group, see [Move subscriptions](../../governance/management-groups/manage.md#move-management-groups-and-subscriptions).
66+
* If you're using Azure Stack Hub, you can't move resources between groups.
67+
* [App Services move guidance](./move-limitations/app-service-move-limitations.md)
68+
* [Azure DevOps Services move guidance](/azure/devops/organizations/billing/change-azure-subscription?toc=/azure/azure-resource-manager/toc.json)
69+
* [Classic deployment model move guidance](./move-limitations/classic-model-move-limitations.md) - Classic Compute, Classic Storage, Classic Virtual Networks, and Cloud Services
70+
* [Cloud Services (extended support) move guidance](./move-limitations/classic-model-move-limitations.md)
71+
* [Networking move guidance](./move-limitations/networking-move-limitations.md)
72+
* [Recovery Services move guidance](../../backup/backup-azure-move-recovery-services-vault.md?toc=/azure/azure-resource-manager/toc.json)
73+
* [Virtual Machines move guidance](./move-limitations/virtual-machines-move-limitations.md)
74+
* To move an Azure subscription to a new management group, see [Move subscriptions](../../governance/management-groups/manage.md#move-management-groups-and-subscriptions).
7375

7476
1. The destination subscription must be registered for the resource provider of the resource being moved. If not, you receive an error stating that the **subscription is not registered for a resource type**. You might see this error when moving a resource to a new subscription, but that subscription has never been used with that resource type.
7577

76-
For PowerShell, use the following commands to get the registration status:
78+
# [CLI](#tab/CLI)
79+
80+
To get the registration status:
7781

78-
```azurepowershell-interactive
79-
Set-AzContext -Subscription <destination-subscription-name-or-id>
80-
Get-AzResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState
81-
```
82+
```azurecli-interactive
83+
az account set -s <destination-subscription-name-or-id>
84+
az provider list --query "[].{Provider:namespace, Status:registrationState}" --out table
85+
```
8286

83-
To register a resource provider, use:
87+
To register a resource provider:
8488

85-
```azurepowershell-interactive
86-
Register-AzResourceProvider -ProviderNamespace Microsoft.Batch
87-
```
89+
```azurecli-interactive
90+
az provider register --namespace Microsoft.Batch
91+
```
92+
93+
# [PowerShell](#tab/PowerShell)
94+
95+
To get the registration status:
8896

89-
For Azure CLI, use the following commands to get the registration status:
97+
```azurepowershell-interactive
98+
Set-AzContext -Subscription <destination-subscription-name-or-id>
99+
Get-AzResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState
100+
```
90101

91-
```azurecli-interactive
92-
az account set -s <destination-subscription-name-or-id>
93-
az provider list --query "[].{Provider:namespace, Status:registrationState}" --out table
94-
```
102+
To register a resource provider:
95103

96-
To register a resource provider, use:
104+
```azurepowershell-interactive
105+
Register-AzResourceProvider -ProviderNamespace Microsoft.Batch
106+
```
97107

98-
```azurecli-interactive
99-
az provider register --namespace Microsoft.Batch
100-
```
108+
---
101109

102110
1. Before moving the resources, check the subscription quotas for the subscription you're moving the resources to. If moving the resources means the subscription exceeds its limits, you need to review whether you can request an increase in the quota. For a list of limits and how to request an increase, see [Azure subscription and service limits, quotas, and constraints](../../azure-resource-manager/management/azure-subscription-service-limits.md).
103111

104112
1. The account moving the resources must have at least the following permissions:
105113

106-
* **Microsoft.Resources/subscriptions/resourceGroups/moveResources/action** on the source resource group.
107-
* **Microsoft.Resources/subscriptions/resourceGroups/write** on the destination resource group.
114+
* **Microsoft.Resources/subscriptions/resourceGroups/moveResources/action** on the source resource group.
115+
* **Microsoft.Resources/subscriptions/resourceGroups/write** on the destination resource group.
108116

109117
1. If you move a resource that has an Azure role assigned directly to the resource (or a child resource), the role assignment isn't moved and becomes orphaned. After the move, you must re-create the role assignment. Eventually, the orphaned role assignment is automatically removed, but we recommend removing the role assignment before the move.
110118

111-
For information about how to manage role assignments, see [List Azure role assignments](../../role-based-access-control/role-assignments-list-portal.yml#list-role-assignments-at-a-scope) and [Assign Azure roles](../../role-based-access-control/role-assignments-portal.yml).
119+
For information about how to manage role assignments, see [List Azure role assignments](../../role-based-access-control/role-assignments-list-portal.yml#list-role-assignments-at-a-scope) and [Assign Azure roles](../../role-based-access-control/role-assignments-portal.yml).
112120

113121
1. **For a move across subscriptions, the resource and its dependent resources must be located in the same resource group and they must be moved together.** For example, a VM with managed disks would require the VM and the managed disks to be moved together, along with other dependent resources.
114122

115-
If you're moving a resource to a new subscription, check to see whether the resource has any dependent resources, and whether they're located in the same resource group. If the resources aren't in the same resource group, check to see whether the resources can be combined into the same resource group. If so, bring all these resources into the same resource group by using a move operation across resource groups.
123+
If you're moving a resource to a new subscription, check to see whether the resource has any dependent resources, and whether they're located in the same resource group. If the resources aren't in the same resource group, check to see whether the resources can be combined into the same resource group. If so, bring all these resources into the same resource group by using a move operation across resource groups.
116124

117-
For more information, see [Scenario for move across subscriptions](#scenario-for-move-across-subscriptions).
125+
For more information, see [Scenario for move across subscriptions](#scenario-for-move-across-subscriptions).
118126

119127
## Scenario for move across subscriptions
120128

@@ -168,50 +176,6 @@ When the move has completed, you're notified of the result.
168176

169177
:::image type="content" source="./media/move-resource-group-and-subscription/view-notification.png" alt-text="Screenshot of the Azure portal displaying a notification with the results of the move operation.":::
170178

171-
### Use Azure PowerShell
172-
173-
#### Validate
174-
175-
To test your move scenario without actually moving the resources, use the [Invoke-AzResourceAction](/powershell/module/az.resources/invoke-azresourceaction) command. Use this command only when you need to predetermine the results.
176-
177-
```azurepowershell
178-
$sourceName = "sourceRG"
179-
$destinationName = "destinationRG"
180-
$resourcesToMove = @("app1", "app2")
181-
182-
$sourceResourceGroup = Get-AzResourceGroup -Name $sourceName
183-
$destinationResourceGroup = Get-AzResourceGroup -Name $destinationName
184-
185-
$resources = Get-AzResource -ResourceGroupName $sourceName | Where-Object { $_.Name -in $resourcesToMove }
186-
187-
Invoke-AzResourceAction -Action validateMoveResources `
188-
-ResourceId $sourceResourceGroup.ResourceId `
189-
-Parameters @{
190-
resources = $resources.ResourceId; # Wrap in an @() array if providing a single resource ID string.
191-
targetResourceGroup = $destinationResourceGroup.ResourceId
192-
}
193-
```
194-
195-
If validation passes, you see no output.
196-
197-
If validation fails, you see an error message describing why the resources can't be moved.
198-
199-
#### Move
200-
201-
To move existing resources to another resource group or subscription, use the [Move-AzResource](/powershell/module/az.resources/move-azresource) command. The following example shows how to move several resources to a new resource group.
202-
203-
```azurepowershell-interactive
204-
$sourceName = "sourceRG"
205-
$destinationName = "destinationRG"
206-
$resourcesToMove = @("app1", "app2")
207-
208-
$resources = Get-AzResource -ResourceGroupName $sourceName | Where-Object { $_.Name -in $resourcesToMove }
209-
210-
Move-AzResource -DestinationResourceGroupName $destinationName -ResourceId $resources.ResourceId
211-
```
212-
213-
To move to a new subscription, include a value for the `DestinationSubscriptionId` parameter.
214-
215179
### Use Azure CLI
216180

217181
#### Validate
@@ -260,6 +224,48 @@ az resource move --destination-group newgroup --ids $webapp $plan
260224

261225
To move to a new subscription, provide the `--destination-subscription-id` parameter.
262226

227+
### Use Azure PowerShell
228+
229+
#### Validate
230+
231+
To test your move scenario without actually moving the resources, use the [Invoke-AzResourceAction](/powershell/module/az.resources/invoke-azresourceaction) command. Use this command only when you need to predetermine the results.
232+
233+
```azurepowershell
234+
$sourceName = "sourceRG"
235+
$destinationName = "destinationRG"
236+
$resourcesToMove = @("app1", "app2")
237+
238+
$sourceResourceGroup = Get-AzResourceGroup -Name $sourceName
239+
$destinationResourceGroup = Get-AzResourceGroup -Name $destinationName
240+
241+
$resources = Get-AzResource -ResourceGroupName $sourceName | Where-Object { $_.Name -in $resourcesToMove }
242+
243+
Invoke-AzResourceAction -Action validateMoveResources `
244+
-ResourceId $sourceResourceGroup.ResourceId `
245+
-Parameters @{
246+
resources = $resources.ResourceId; # Wrap in an @() array if providing a single resource ID string.
247+
targetResourceGroup = $destinationResourceGroup.ResourceId
248+
}
249+
```
250+
251+
If the validation is successful, no output is displayed. However, if the validation fails, an error message will appear, explaining the reasons why the resources cannot be moved.
252+
253+
#### Move
254+
255+
To move existing resources to another resource group or subscription, use the [Move-AzResource](/powershell/module/az.resources/move-azresource) command. The following example shows how to move several resources to a new resource group.
256+
257+
```azurepowershell-interactive
258+
$sourceName = "sourceRG"
259+
$destinationName = "destinationRG"
260+
$resourcesToMove = @("app1", "app2")
261+
262+
$resources = Get-AzResource -ResourceGroupName $sourceName | Where-Object { $_.Name -in $resourcesToMove }
263+
264+
Move-AzResource -DestinationResourceGroupName $destinationName -ResourceId $resources.ResourceId
265+
```
266+
267+
To move to a new subscription, include a value for the `DestinationSubscriptionId` parameter.
268+
263269
### Use Python
264270

265271
#### Validate
@@ -283,26 +289,24 @@ resources_to_move = ["app1", "app2"]
283289
destination_resource_group = resource_client.resource_groups.get(destination_name)
284290

285291
resources = [
286-
resource for resource in resource_client.resources.list_by_resource_group(source_name)
287-
if resource.name in resources_to_move
292+
resource for resource in resource_client.resources.list_by_resource_group(source_name)
293+
if resource.name in resources_to_move
288294
]
289295

290296
resource_ids = [resource.id for resource in resources]
291297

292298
validate_move_resources_result = resource_client.resources.begin_validate_move_resources(
293-
source_name,
294-
{
295-
"resources": resource_ids,
296-
"target_resource_group": destination_resource_group.id
297-
}
299+
source_name,
300+
{
301+
"resources": resource_ids,
302+
"target_resource_group": destination_resource_group.id
303+
}
298304
).result()
299305

300306
print("Validate move resources result: {}".format(validate_move_resources_result))
301307
```
302308

303-
If validation passes, you see no output.
304-
305-
If validation fails, you see an error message describing why the resources can't be moved.
309+
If the validation is successful, no output is displayed. However, if the validation fails, an error message will appear, explaining the reasons why the resources cannot be moved.
306310

307311
#### Move
308312

@@ -325,18 +329,18 @@ resources_to_move = ["app1", "app2"]
325329
destination_resource_group = resource_client.resource_groups.get(destination_name)
326330

327331
resources = [
328-
resource for resource in resource_client.resources.list_by_resource_group(source_name)
329-
if resource.name in resources_to_move
332+
resource for resource in resource_client.resources.list_by_resource_group(source_name)
333+
if resource.name in resources_to_move
330334
]
331335

332336
resource_ids = [resource.id for resource in resources]
333337

334338
resource_client.resources.begin_move_resources(
335-
source_name,
336-
{
337-
"resources": resource_ids,
338-
"target_resource_group": destination_resource_group.id
339-
}
339+
source_name,
340+
{
341+
"resources": resource_ids,
342+
"target_resource_group": destination_resource_group.id
343+
}
340344
)
341345
```
342346

0 commit comments

Comments
 (0)