Introduction
Azure subscription is like a prepaid account. You required balance in it before utilizing its resourses. Sometime its account balance (Azure credits) is going to expire, and once it goes to zero you will not be able to use its resources, until you will refill account again.
If you have more than one azure subscription and you don’t want to refill your account, you can move your resource from one account to another account. Here we are migrating Azure VM from one Azure subscription to another subscription. Please note, if any of your subscription is disabled, due to zero credits, this migration will not work.
Steps to Migrate a VM on another subscription
This process contains the following three steps:
- Migrating VM’s blob on another subscription.
- Create a new disk on target subscription for the blob.
- Create the Virtual Machine with the created disk.
Migrating VM’s blob on another subscription
To migrate blob which is used by Virtual machine, follow the steps in PowerShell.
Connect to Subscription by PowerShell
- Type Add-AzureAccount command in PowerShell, a window will open, enter your email address here which has the subscription.

- On next page, enter your credentials to log in in to your Azure account.

- Now you can use PowerShell to work with your account.
Get the subscriptions details
Get-Azure Subscription: This command lists all the subscriptions which are associated with your email

Get the current Subscription
Get-AzureSubscription-Current: If you have more than one subscription to get the current one execute the following command.

Get the Current subscription id
(Get-AzureSubscription -Current).SubscriptionId
Set current Subscription
If you have more than one subscription, and your current subscription is different from your required subscription, then set your desired subscription as the current subscription:
By Name:
Select-AzureSubscription -SubscriptionName anmolbadaya –Current
Here anmolbadaya is my Subscription Name
By ID:
Select-AzureSubscription -SubscriptionId 03672ab6-f116-4ba1-91de-a085d0f07402 –Current
Here 03672ab6-f116-4ba1-91de-a085d0f07402 is my subscription id.
For more details refer link.
List all virtual machines in current Subscription
Get-AzureVM
It will display all VMs with service name and VM name. Please check VM which you want to migrate and exist here.

To Know a VM’s Storage Account Name
To migrating a VM we require VM storage account name, execute the following command to get it.
- $disk = Get-AzureDisk | Where-Object { $_.AttachedTo.RoleName -eq "VMName" }
- $mediaLink = $disk.MediaLink
- $storageAccountName = $mediaLink.Host.Split('.')[0]
- $storageAccountName
Get container and vhd file details of your VM
To migrate a VM we also container name and vhd file name. Get it by the following command:
Get-AzureVM –ServiceName “anmolwin8vs” –Name “anmolwin8vs” | Get-AzureOSDisk

MediaLink value is the complete path of vhd file; you can see vhd file name here with .vhd extension and container name just before .vhd file. Here container name is vhds, and VHD file name is anmolwin8vs-anmolwin8vs-2015-09-01.vhd.
VHD blob copy from one Subscription to other
- # Source VHD blob#
- $blobName = "vhd file name"
- # Provide Source Storage Account details #
- $sourceStorageAccountName = "source Account name"
- $sourceAccountKey = "Source Storage Account Key"
- $sourceAccountContext = New-AzureStorageContext –StorageAccountName $sourceStorageAccountName -StorageAccountKey $sourceAccountKey
- $sourceContainer = "Container Name"
- # Provide Destination Storage Account Details #
- $destinationStorageAccountName = "Destniation Account Name"
- $destinationAccountKey = "Destination Storage Account Key"
- $destinationContext = New-AzureStorageContext –StorageAccountName $destinationStorageAccountName -StorageAccountKey $destinationAccountKey
- # Copy the blob #
- $blobCopy = Start-AzureStorageBlobCopy -DestContainer $destinationContainerName `
- -DestContext $destinationContext `
- -SrcBlob $blobName `
- -Context $sourceContext `

















Santhakumar MunuswamyPosted Sep 17, 2015, 10:29 AM
Thanks for nice article:)
Mohammed IbrahimPosted Sep 15, 2015, 8:04 PM
nice
Harshad PansuriyaPosted Sep 15, 2015, 6:23 AM
Nice One