Skip to content

Instantly share code, notes, and snippets.

@aquiladev
Last active November 21, 2015 14:52
Show Gist options
  • Save aquiladev/ec1e4b2377c3dd116960 to your computer and use it in GitHub Desktop.
Save aquiladev/ec1e4b2377c3dd116960 to your computer and use it in GitHub Desktop.
Windows Azure : Copy VHD between subscriptions
# NOTES: -Source storage should be "Public Container"
# -Doesn't matter which subscription selected
### This assumes you have already imported the azure publishsettings file and the subscriptions are known on your machine.
Select-AzureSubscription -SubscriptionId "2fcd3fbe-9046-4dd3-8916-329df55b6d64"
### Defines the location of the VHD we want to copy
$sourceVhdUri = "https://storage1.blob.core.windows.net/vhds/x1.vhd"
### Defines the source Storage Account
$sourceStorageAccountName = "storage1"
$sourceStorageKey = "1dslgkjkl=="
### Defines the target Storage Account
$destStorageAccountName = "storage2"
$destStorageKey = "2dslgkjkl=="
### Create a context for the source storage account
$sourceContext = New-AzureStorageContext –StorageAccountName $sourceStorageAccountName `
-StorageAccountKey $sourceStorageKey
### Create a context for the target storage account
$destContext = New-AzureStorageContext –StorageAccountName $destStorageAccountName `
-StorageAccountKey $destStorageKey
### Name for the destination storage container
$containerName = "vhds"
### Create a new container in the destination storage
#New-AzureStorageContainer -Name $containerName -Context $destContext
### Start the async copy operation
$blob1 = Start-AzureStorageBlobCopy -SrcUri $sourceVhdUri `
-SrcContext $srcContext `
-DestContainer $containerName `
-DestBlob "x1.vhd" `
-DestContext $destContext
### Get the status of the copy operation
$status = $blob1 | Get-AzureStorageBlobCopyState
### Output the status every 10 seconds until it is finished
While($status.Status -eq "Pending"){
$status = $blob1 | Get-AzureStorageBlobCopyState
Start-Sleep 10
$status
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment