Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheBigBear/a7d881f057200078fcb77a34f1b878ea to your computer and use it in GitHub Desktop.
Save TheBigBear/a7d881f057200078fcb77a34f1b878ea to your computer and use it in GitHub Desktop.
Move_Azure_Virtual_Machine_to_a_different_data_center
Get-AzureVM -ServiceName "name_cloud_service" -Name "vm_name"
Get-AzureVM -ServiceName "name_cloud_service" -Name "vm_name" | Get-AzureEndpoint
#Get Associated VHD
Get-AzureDisk | Where-Object {$_.AttachedTo.RoleName –eq "vm_name" } | SELECT MediaLink
Stop-AzureVM -Name "vm_name" -ServiceName "name_cloud_service" -Force
Remove-AzureVM -Name "vm_name" -ServiceName "name_cloud_service"
New-AzureStorageAccount -StorageAccountName "storage_name" -Label "storage_name" -Location "your_location"
#Source storage account
$context1 = new-azurestoragecontext -storageaccountname "name_source_account" -storageaccountkey "key_source_account"
#Destination storage account
$context2 = new-azurestoragecontext -storageaccountname "name_destination_account" -storageaccountkey "key_destination_account"
#Initiate copy this might take a while
Start-AzureStorageBlobCopy -SrcContainer "vhds" -SrcBlob "name_as_found_in_step_one.vhd" -SrcContext $context1 -DestContainer "vhds" -DestBlob "my_destination_name.vhd" -DestContext $context2
$context2 = new-azurestoragecontext -storageaccountname "name_destination_account" -storageaccountkey "key_destination_account”
Get-AzureStorageBlobCopyState -Blob "file_name.vhd" -Container "vhds" -Context $context2
$context2 = new-azurestoragecontext -storageaccountname "name_destination_account" -storageaccountkey "key_destination_account”
Stop-CopyAzureStorageBlob -Blob "file_name.vhd" -Container "vhds" -CopyId "Value_from_Get-AzureStorageBlobCopyState" -Context $context2
#Additional required step
Set-AzureSubscription -SubscriptionName "your_subscription" -CurrentStorageAccount "name_storage_account"
#Build VM Config
$vmdetails = New-AzureVMConfig -Name "vm_name" -InstanceSize your_instance_size -ImageName "name_of_the image"
#Additonal settings...
#Create the VM
New-AzureVM –ServiceName "name_cloud_service" -Location "location" -VMs $vmdetails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment