0

I am attempting to move a resource group (that contains a VM with its dependant resources e.g. network interface etc) to a new subscription and resource group. (the move works fine if done via the GUI)

My Script:

foreach ($resource in $resources) {Move-AzureRmResource
-DestinationResourceGroupName "newresourcegroup" -ResourceId $resource.resourceID -DestinationSubscriptionId 123456}

Its failing with

Move-AzureRmResource : {"error":{"code":"ResourceMoveProviderValidationFailed","message":"Resource move validation failed. Please see details. Diagnostic information: timestamp

etc...

"The move resources request does not contain all the dependent resources. Please check error details for missing resource ids.\"}],\"code\":\"MissingMoveDependentResources\",\"message\":\"The move resources request does not contain all the dependent resources. Please check error details for missing resource ids.\"}}"},{"target":"Microsoft.Network/networkInterfaces","message":"{\"error\":{\"code\":\"MissingMoveDependentResources\",\"message\":\"The move resources request does not contain all the dependent resources. Please check details for missing resource Ids

Clearly I need to specify the dependant resources somehow, but there doesn't appear to be a parameter for "dependant resources" for the Move-AzureRmResource module.

a. How can I determine what the dependant resources are?

b. How do I specify them in the move cmdlet?

leo_cape
  • 141
  • 3
  • 14

2 Answers2

1

The move resources request does not contain all the dependent resources

According to your scripts, it seems that you just traverse through resources and move them one by one to another resource group in new subscription. But as we know, some resource may have some dependent resources, to move this type of resource (such as virtual machine etc), we should make sure we also move all of the dependent resources, otherwise, the move operation will fail.

Before moving services, we need to know what services that enable move and limitations. Besides, please refer to Use Powershell to move a VM to know how to move resource that requires the dependent resources.

Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • Thanks for the linksFred, the script is this: Move-AzureRmResource -DestinationResourceGroupName $destinationRG -ResourceId $vm.ResourceId, $storageAccount.ResourceId, $diagStorageAccount.ResourceId, $vNet.ResourceId, $nic.ResourceId, $ip.ResourceId, $nsg.ResourceId – leo_cape Mar 01 '17 at 05:10
  • If you are just moving infrastracture resources like VM, VNet, NIC, etc. then it might be easier to copy VHDs attached to VM to storage account in new subscription and use template deployment. The template will already contain all current configurations and with existing VHDs you can recreate entire resource group as is. To get your current template go to your Resource Group's blade in Azure Portal and then go to Automation script. – Tomasz Tuczapski Mar 01 '17 at 08:34
  • Thanks Tomasz, in this instance it is way quicker to just use the powershell move command as mentioned above.. – leo_cape Mar 02 '17 at 07:20
0

I would add that a move to a new subscription requires that dependent resources be moved at the same time. This requires first organizing resources in the same RG (at this time anyway) before the move operation can succeed. If you are merely moving resources between RGs, then you could do the move without a re-org in your RGs. Remember you may have VM extensions that are hidden objects that can fail, and things like Azure Backup that would need to be addressed before and after the move.

  1. Answer:Here is a REST validation that can be performed to identify dependent resources before attempting the move. https://learn.microsoft.com/en-us/rest/api/resources/resources/validatemoveresources
  2. You could then get the Resource IDs using: "$Ids = Get-AzureRMResource -ResourceGroupName $sourceRgName.ResourceGroupName | Select-Object ResourceId" then move using "Move-AzureRmResource -DestinationResourceGroupName $targetRg.ResourceGroupName -DestinationSubscriptionId $AzureTargetSubscription.SubscriptionId -ResourceId $Ids.ResourceID"