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.