So I had to move a lot of resources from one of my subscriptions to another and thought, how hard can it be. Well I started to look around in the Azure portal and realized I couldn’t move between subscriptions at all. So I did some googling and found this article from Microsoft on how to move resources. I can recommend reading it to find the limitations of which resources can and can’t be moved.
Unfortunately the article only showed how to move single resources instead of entire subscriptions so I wrote a little PowerShell script to move all resources inside a resource group.
One prerequisite is that the destination resource group must already be created.
1$sourceSubId = "11111111-1111-1111-1111-111111111111" # Subscription you want to move resources from2$destSubId = "22222222-2222-2222-2222-222222222222" # Subscription you want to move resources to34$sourceResourceGroup = "ResourceGroupOld" # Name of the resource group your moving resources from5$destResourceGroup = "ResourceGroupNew" # Name of the resource group your moving resources to67$nonMovableTypes = @('microsoft.insights/components','Microsoft.ClassicStorage/storageAccounts','Microsoft.Compute/virtualMachines/extensions','Microsoft.Sql/servers/databases') # These are the types that cannot be moved8$typeToMoveSeparate = @() # These are the types that must be moved separately910try11{12 Select-AzureRmSubscription -SubscriptionId $sourceSubId1314 $groupResources = Find-AzureRmResource -ResourceGroupNameContains $sourceResourceGroup15 $resourceIds = @()16 $moveSeparateResources = @()1718 foreach ($r in $groupResources)19 {20 if ($nonMovableTypes.Contains($r.ResourceType)) {21 continue22 }2324 if ($typeToMoveSeparate.Contains($r.ResourceType)) {25 $moveSeparateResources = $moveSeparateResources + $r;26 } else {27 $resourceIds = $resourceIds + $r.ResourceId;28 }29 }3031 if ($resourceIds.Count.Equals(0) -and $moveSeparateResources.Count.Equals(0))32 {33 "No resources to move"34 }35 else36 {37 if (!$resourceIds.Count.Equals(0)) {38 "Started moving " + $resourceIds.Count + " resources";39 Move-AzureRmResource -DestinationResourceGroupName $destResourceGroup -ResourceId $resourceIds -DestinationSubscriptionId $destSubId -Verbose40 }4142 foreach ($r in $moveSeparateResources) {43 "Moving type " + $r.ResourceType + ""44 Move-AzureRmResource -DestinationResourceGroupName $destResourceGroup -ResourceId $r.ResourceId -DestinationSubscriptionId $destSubId -Verbose45 }4647 "Move done!"48 }49}50catch51{52 Write-Error($_)53}
If you’ve just created your new subscription you might get an error like this one
MissingRegistrationsForTypes : The subscription ‘xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx’ is not registered for resource types ‘Microsoft.Web/sites.‘
To solve it you need to register the resource type this can be done with the following commands:Select-AzureRmSubscription -SubscriptionId “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx”
Register-AzureRmResourceProvider -ProviderNamespace Microsoft.Web