categories: [ Azure ] tags: [ Application Insights ] [ Azure ] [ PowerShell ]
created: 03 Jan 2018 @ 11:10 modified: 03 Jan 2018 @ 11:23
There is documentation available for Move resources to new resource group or subscription but things are easier to do with exact sample code so here it goes . The steps below will work for moving between Resource Groups as well, you'll just skip some steps that would be obvious.
There are a couple limitations which make sense like resources needing to be in the same directory and not every services is supported to move which is all detailed on the link mentioned above where all the limitations are documented.
Step by Step
First off we need to login
Then let's list all our subscriptions that we have access to
You should see a result similar to the below
Now we need to set the source and destination subscription id from the list above and then check if the resource type is registered in the destination subscription
Once done we can check the resource providers to make sure the insights resource provider is enabled, usually this would not be enabled if you haven't created the resource in the destination subscription before. We'll first change the context to the subscription to our destination subscription id and then list the resource providers
If like with me it's not registered
you can use the script below to enable the provider
you should see a message like below saying it's Registering
This takes a little while to run sometimes, you can run the last part of the script above every now and then to see when it's registered
You should see it saying Registered as below when done
Before doing the switch we need to make sure we have a resource group in the target subscription to move the resource to, you can create a new resource group like below
We can now get our source resource Id and perform the move. For this we are going to switch context to the source subscription, find the resource we want, get it's resource id and then finally call Move-AzureRmResource to move the resource
This would take a little while to complete usually, when done your resource should be in the subscription you want it in...if you there's a good chance you going to be creating a support ticket soon . This is where you would leave off the subscription id if you are moving between resource groups instead of subscriptions
All that's left now is to go through any dashboards and existing scripts that reference this resource and update them. Because the resource is no longer at it's old location your dashboards will become less 'metricky'
The full script for the above is below including some variables to make the replacements easier
There is quite a lot of functionality that is available to us using the sdks like PowerShell that we can't do in the Azure Portal UI. Sometimes you just need to figure it out, in this case there was a good doc to follow.