while moving all resources from Resource group from once subscription to another subscription, getting error message as below.
{"code":"ResourceMoveProviderValidationFailed","target":"Microsoft.Web/serverFarms","message":"{"Code":"BadRequest","Message":"Please select all the Microsoft.Web resources from 'rg_cdp_plc_dev' resource group for cross-subscription migration. Also, please ensure destination resource group 'Test-dev-rg' doesn't have any Microsoft.Web resources before move operation. Here is the list of resources you have to move together: cdpapp (Microsoft.Web/sites)\r\n cdpapp-demo (Microsoft.Web/sites)\r\n cdpapp-api (Microsoft.Web/sites)\r\n cdpapp-stg (Microsoft.Web/sites). This resource is located in resource group 'rg_cdp_plc_dev', but hosted in the resource group 'rg_cdp_plc_stg'. This may be a result of prior move operations
but all resources are in single RG.
$sourceResourceGroupName = "rg_cdp_plc_dev"
$targetResourceGroupName = "Test-dev-rg"
$targetSubscriptionId = "<TargetSubscriptionId>"
$resources = Get-AzResource -ResourceGroupName $sourceResourceGroupName | Where-Object { $_.ResourceType -eq 'Microsoft.Web/sites' -or $_.ResourceType -eq 'Microsoft.Web/serverFarms' }
$resourceIds = $resources.ResourceId
Move-AzResource -DestinationResourceGroupName $targetResourceGroupName -DestinationSubscriptionId $targetSubscriptionId -ResourceId $resourceIds
For Azure CLI, use the az resource move
command:
target_rg="Test-dev-rg"
target_subscription="<TargetSubscriptionId>"
resource_ids=$(az resource list --resource-group $source_rg --query "[?contains(type, 'Microsoft.Web')].id" -o tsv)
az resource move --destination-group $target_rg --destination-subscription-id $target_subscription --ids $resource_ids