The ramblings of an old IT Pro travelling the digital byways.

Tuesday, June 21, 2016

Move Azure Resources

Sometimes it becomes necessary to move an Azure resource from one resource group to another within a subscription.  While this is technically not difficult, it can be a bit of a pain.  Let's let the computers do what they do best.

Following is a quick PowerShell script.  It assumes you've already authenticated to your subscription (Login-AzureRmAccount) and selected the appropriate context (Select-AzureRMSubscription).

Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.122
Created on:   5/19/2016 3:11 PM
Created by:   TowerBE
Organization: XXXXXXX
Filename:             move-resource.ps1
Moves an Azure Resource.

A quick and dirty script to move an Azure resource from one Resource
Group to another

The name of the Azure Resource to be moved.

The name of the Azure Resource Group where the resource currently exists.

The name of the Azure Resource Group where you're moving the resource.

move-resource.ps1 -resName "myservicebus" -oldRg "busted" -newRg "hotness"
This will move the resource myservicebus from the busted resource group
to the hotness resource group.

[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]

$resource = Get-AzureRmResource -ResourceName "$resName" -ResourceGroupName "$oldRg"
Move-AzureRmResource -DestinationResourceGroupName "$newRg" -ResourceId $resource.ResourceId

Please note that not all resources can be moved, and not all resources support moving fully.  I've used this script for moving storage accounts, service bus namespaces and other resources types, but don't make any guarantees. If you want to read more about moving resources, go to

No comments:

About Me

My photo
A living, breathing contradiction.