How to move all Azure resources from resource group by Azure CLI?

Khalid Hajjouji 50 Reputation points
2025-06-12T15:48:56.64+00:00

How to move all Azure resources from a resource group to another resource group by Azure CLI?

I try this code below but it doesnt work

az login --service-principal --username 'someGUID' --password 'someSecret' --tenant 'tenantGuid'

az account set --subscription 'sourceSubscriptionGUID'

az resource move --destination-group 'desinationResourceGroupName' --destination-subscription-id 'destinationSubscriptionGUID' --ids $(az resource show --name --resource-group  --query id -o tsv)

Azure DevOps
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Durga Reshma Malthi 4,430 Reputation points Microsoft External Staff Moderator
    2025-06-12T15:56:33.1566667+00:00

    Hi Khalid Hajjouji

    Could you please try the below commands

    az login --service-principal --username 'someGUID' --password 'someSecret' --tenant 'tenantGuid'
    az account set --subscription 'sourceSubscriptionGUID'
    az resource move --destination-group 'destinationResourceGroupName' --destination-subscription-id 'destinationSubscriptionGUID' --ids $(az resource list --resource-group 'sourceResourceGroupName' --query "[].id" -o tsv)
    

    Alternatively, you can try the below commands

    # 1. Login with service principal
    az login --service-principal --username 'someGUID' --password 'someSecret' --tenant 'tenantGuid'
    # 2. Set source subscription
    az account set --subscription 'sourceSubscriptionGUID'
    # 3. Gather all resource IDs in the source resource group
    RESOURCE_IDS=$(az resource list --resource-group <source-rg-name> --query "[].id" -o tsv)
    # 4. Move resources
    az resource move \
      --destination-group <destination-rg-name> \
      --destination-subscription-id <destination-subscription-id> \
      --ids $RESOURCE_IDS
    

    Hope this helps!

    Please Let me know if you have any queries.

    If you found the information helpful, please click "Upvote" on the post to let us know and consider accepting the answer as the token of appreciation. Thank You.

    1 person found this answer helpful.
    0 comments No comments

  2. Khalid Hajjouji 50 Reputation points
    2025-06-13T07:09:09.0533333+00:00

    thanks it works


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.