Move Azure resource to another subscription with the Azure Cloud Shell

A couple of days ago I wanted to tidy up my Azure subscription and move the unneeded resources from my active subscription to my team’s subscription. At first I wanted to move a storage account, which I created a couple of years ago - needless to say that this was of type classic resource. The Azure portal now introduced a quite handy operation which can be used for many resources in order to move the resource either to another resource group or even to another subscription. Yeah I know what you think right now - AWESOME.

/static/img/move_to_arm01.png

So as I hit the “Move” button in the Azure portal in order to move the account to another subscription I got the following error:

/static/img/move_to_arm02.png

And there it was - the problem of classic resource type migrations. So I searched a bit and had the idea of doing all needed operations within the Azure Cloud Shell. So let’s start off by opening the shell and registering a migration resource provider and set up the preparations for the migration of the storage account.

azure provider register Microsoft.ClassicInfrastructureMigrate
azure provider show Microsoft.ClassicInfrastructureMigrate
azure config mode arm
azure storage account prepare-migration <storageAccountName>

After runnning the last command you should see something like this in the Azure Cloud Shell:

/static/img/move_to_arm03.png

So now let’s do the migration by entering the following command which should lead to the following output:

azure storage account commit-migration <storageAccountName>

/static/img/move_to_arm04.png

So we have migrated the storage account from type classic to resource manager type. And now we are good to go to move the storage account to another subscription. And as we already have our shell session open let’s do this via the cloud shell as well. Just enter the following command and make a note of the ID:

az resource show -g <resourceGroupName> -n <storageAccountName> --resource-type "Microsoft.Storage/storageAccounts" --query id

/static/img/move_to_arm05.png

And now finally we can move the resource to the destination subscription with the following command:

az resource move --destination-group <resourceGroupName> --ids <resourceID> --destination-subscription-id <destinationSubscriptionID>

/static/img/move_to_arm06.png

This command will take a while to complete, but if you watch the destination resource group you will likely see the following message “Moving resources” as the following illustration shows:

/static/img/move_to_arm07.png

And when the command is completed successfully you have moved your storage account. Of course you are not limited to storage accounts only, but you can move almost any service in the ARM world between resource groups or subscription. If you want to know how to move another resource type, just give me short notice below or on Twitter and I will follow up on that! Cheers…