1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
$username = "userid@yourtenantname.onmicrosoft.com" $password = ConvertTo-SecureString "yourpassword" -AsPlainText -Force $cred = new-object -typename System.Management.Automation.PSCredential ` -argumentlist $username, $password Add-AzureAccount -Credential $cred $servicename = "yourservicename" $vmname = "yourvmname" # maybe this should be another task altogether # Get-AzureVM -ServiceName $servicename -Name $vmname | Stop-AzureVM -force Select-AzureSubscription "yoursubscriptionname" Set-AzureSubscription -SubscriptionName "yoursubscriptionname" -CurrentStorageAccount "portalvhdssomethingsource" # VHD blob to copy # $blobName = "yourvhdname.vhd" # Source Storage Account Information # $sourceStorageAccountName = "portalvhdssomethingsource" $sourceKey = "yourkey" $sourceContext = New-AzureStorageContext –StorageAccountName $sourceStorageAccountName -StorageAccountKey $sourceKey $sourceContainer = "vhds" # Destination Storage Account Information # $destinationStorageAccountName = "portalvhdssomethingdestination" $destinationKey = "yourkey" $destinationContext = New-AzureStorageContext –StorageAccountName $destinationStorageAccountName -StorageAccountKey $destinationKey # Create the destination container # $destinationContainerName = "vhds" # Copy the blob # $blobCopy = Start-AzureStorageBlobCopy -DestContainer $destinationContainerName ` -DestContext $destinationContext ` -SrcBlob $blobName ` -Context $sourceContext ` -SrcContainer $sourceContainer -Force while(($blobCopy | Get-AzureStorageBlobCopyState).Status -eq "Pending") { Start-Sleep -s 30 $blobCopy | Get-AzureStorageBlobCopyState } # maybe this should be another task altogether # Get-AzureVM -ServiceName $servicename -Name $vmname | Start-AzureVM # set as a disk # $AzureVHD = 'http://' + $destinationStorageAccountName + '.blob.core.windows.net/' + $destinationContainerName + '/' + $blobName Add-AzureDisk -DiskName $vmname -MediaLocation $AzureVHD ` -Label $vmname -OS linux |