Windows – Is it possible to migrate Azure VM image from one Subscription to another Subscription

azurepowershellvirtual-machineswindows

I recently captured one azure vm image in one storage account, and planning to migrate this image to another storage account under a different subscription. I used PowerShell Script to run this task, but I came across with this problem: The storage account was not found. And one more concern is that PowerShell has to be related to the specific Azure Account, otherwise it can not run script. So the story is how to use PowerShell control different subscriptions at the same time, and also perform the migration task??
Thank You.

BTW, the PowerShell script is shown below:

Change these to match the source account

$sourceStorageAccountName = ""
$sourceContainerName = ""
$sourceStorageKey = "" #Need this if moving data from a different subscription

Destination Account Information

$destStorageAccountName = Read-Host "Enter Destination Storage Account Name"
$destStorageAccountKey = Get-AzureStorageKey $destStorageAccountName | %{$_.Primary}
$destContainerName = Read-Host "Enter Destination Container Name"

$sourceContext = New-AzureStorageContext -StorageAccountName $sourceStorageAccountName -StorageAccountKey $sourceStorageKey -Protocol Http
$destContext = New-AzureStorageContext -StorageAccountName $destStorageAccountName -StorageAccountKey $destStorageAccountKey

$uri = $sourceContext.BlobEndPoint + $sourceContainerName +"/"

Copy Operation

Get-AzureStorageBlob
-Context $sourceContext

-Container $sourceContainerName |
ForEach-Object
{ Start-AzureStorageBlobCopy

-SrcUri "$uri$($_.Name)"
-DestContext $destContext

-DestContainer $destContainerName
-DestBlob "hackathon/$($_.Name)"

}

Checking Status of Blob Copy — This can be commented out if no confirmation is needed

Get-AzureStorageBlob
-Context $sourceContext

-Container $sourceContainerName |
ForEach-Object
{ Get-AzureStorageBlobCopyState

-Blob $_.Name
-Context $destContext

-Container $destContainerName
-WaitForComplete

}

The problem is like this:
Get-AzureStorageKey : No current subscription has been designated. Use
Select-AzureSubscription -Current to set the current
subscription.

Best Answer

Azure provides little support for switching any Azure service from one Subscription to another.

If you create a ticket, I have done this by the way, you can have Azure support staff manually switch ALL services from one Subscription (source) to another Subscription (destination) where the destination Subscription has NO services in that Subscription.

You CANNOT select individual services from the source Subscription to transfer, to the destination Subscription (its all or nothing from the source Subscription) and you CANNOT have any existing services in the destination Subscription.

**A service is any Azure feature (VM, Website, Storage Blob etc)

It is likely that the support rep has not done this procedure before and you will have to let them know it is possible, my support rep for the ticket took about a week to figure it all out. Make sure you use the vernacular source Subscription and destination Subscription with GUIDs for both Subscriptions in all conversations with the Azure support rep.

Now for a VM in particular, it looks like you can copy a VM from one storage account to another using a tool called AzCopy, check out this article:

http://thecodejunkie.com/2014/01/20/copying-virtual-machines-between-azure-subscriptions/

Related Topic