Saturday, April 26, 2014

Stop copy of Azure Virtual Machine from one subscription to another subscription using Azure Powershell

Technologies - Azure Blob sorage and Poweshell sdk 2.3 and above...

If you wish to take back up of azure virtual machine, the best way is to use Windows Azure Powershell cmdlets. Also there is an excellent post written about copying the azure virtual machine across subscriptions here -

However sometimes it may happen that you start copying of Azure Virtual machine to a storage account and finds that the selected storage account is not the intended one. Then you might want to stop the copy operation of azure virtual machine immediately. In such case following guide will help you to stop the copy operation of virtual machines.
The copy operation can be started with powershell command Start-CopyAzureStorageBlob.
Similarly to stop Azure blob copy operation we have Stop-AzureStorageBlobCopy command.

Let’s walkthrough the each step required to stop the blob copy operation in case of Azure virtual machine or in case of any blob copy operation. The same steps can be used for soppting all types of blob copy operation and it is not specific for stopping azure virtual machine vhd copy.

Set subscription first using following command –
Select-AzureSubscription -SubscriptionName "Your Destination Subscription Name"

Destination subscription is the Azure subscription under which you have started the copy operation of Azure blob.
For example, you have subscritopn1 and subscription2. You have started copy the virtual machine vhd from storage of subscription1 to subscription2 then copy operation has to be stopped in subscription2. Hence destination subscription name will be subscription2 under which you are copying the blob, has to be given in above command. If you are copying to different storage account in same subscription then your source and destination subscription name will be same.

Retrieve the storage account details of destination subscription under which copy operation is in porgress and its associated primary key – 

$destStorageAccount = Get-AzureStorageAccount -StorageAccountName “destination storage account name”

$destStorageKey = (Get-AzureStorageKey -StorageAccountName "destination storage account name").Primary

Set the storage context information as below –

$destContext = New-AzureStorageContext -StorageAccountName “destination storage account name” -StorageAccountKey $destStorageKey 

Then we need to fire the Stop-AzureStorageBlobCopy command to stop the copy operation in container – 

Get-AzureStorageBlob -Container vhds -Context $destContext | Stop-AzureStorageBlobCopy –Force

This stop the pending copy operation on blobs present in the container.

Hope this helps…



  1. Thanks for your blog post! I needed to know on what storage account to stop the copy operation and found the answer here.

  2. You know your projects stand out of the herd. There is something special about them. It seems to me all of them are really brilliant! Best Copy Machines for Business