Migrate VMs between Azure subscriptions

Azure provide a very poor mechanism to share VM images between subscriptions, while Amazon could easily share images between account.

The following page provide enough PowerShell to automate the whole process, but it can’t work if we have VNet configuration for source VM.

http://blogs.msdn.com/b/microsoft_press/archive/2014/01/29/from-the-mvps-copying-a-virtual-machine-from-one-windows-azure-subscription-to-another-with-powershell.aspx

I revise and add support on VNet configuration, and package scripts to a file.

https://github.com/tombwu/AzureLab/blob/master/CopyVmBetweenSubscriptions.ps1

Just use a command as below, you may migrate VM to another subscription.

.\CopyVmBetweenSubscriptions.ps1 -SourceVmName SrcDevBox -SourceServiceName SrcDevBox -SourceSubscriptionName “Sub1” -TargetServiceName DevBox2 -TargetSubscriptionName “Sub2”

Enjoy it!

Advertisements

Migrate Windows Server from AWS EC2 to Azure

I need to migrate several Windows VMs from AWS EC2 to Windows Azure.

The general practice AWS provide is using EC2 Exporting service to export VHD for EC2 instance.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ExportingEC2Instances.html

After I set up many environment variables,S3 bucket and permission for VM export account, I am able to run export command on EC2 CLI. But it is disappointing that the error message “Only imported instances can be exported.” showed.

Then I head to another solution to make VHD inside the Windows server by using a tool Disk2vhd.

https://technet.microsoft.com/en-us/library/ee656415.aspx

It is pretty easy to export VHD by the tool.

With VHD ready, now I could use Azure Powershell to upload VHD file (Add-AzureVHD command will convert VHD to fix type automatically), create OS disk from VHD and create VM instance from the disk.

So far I suspect that it is most fast way to move VM from EC2 to Azure if you could log in the Windows Server.

Build complex cross Azure subscription Windows lab by using Azure Site to Site VPN

Azure Site to Site VPN (S2S VPN) started as a method to connect Azure VNet and on premise network. Now it appears as a good solution to connect Azure VNets as well.

https://azure.microsoft.com/zh-cn/documentation/articles/virtual-networks-configure-vnet-to-vnet-connection/

http://azure.microsoft.com/blog/2014/06/17/vnet-to-vnet-connecting-virtual-networks-in-azure-across-different-regions/

Equipped with Azure S2S VPN, we are able to build more complex Windows lab across Azure subscriptions. The diagram below show the idea. Compare to P2S VPN, S2S VPN is a much stable solution and could reserve static IP Address for DNS and Domain Controller.

Azure Site to Site VPN

The steps to make that happen are:

1. Create VNet per subscription.

2. Create gateway for each VNet. You may need to export VNetConfig, manually add local network and import config at first before that.

3. Create local network and build connection for each VNet. You must use VNetConfig file to do that. And gateway should be provisioned already as local network will need that.

4. Make all the VPN connection share the same gateway sharedkey.

Step 3 and step 4 will be very time-consuming as you need to create N*(N-1) local network if you have N VNet to connect together. I wrote a script to make step 2-4 automated.

All you need to do are step 1 + a .csv file to describe VNets + SharedKey.

The csv file looks like

Subscription,VNetName,AddressPrefix,GatewaySubnet
Sub-Center,centerVnet,10.0.2.0/24,10.0.2.32/27
Sub-West,westVnett,10.0.1.0/24,10.0.1.32/29
Sub-East,eastVnet,10.0.3.0/24,10.0.3.128/28
Sub-South,southVnet,192.168.0.0/24,192.168.0.160/28

AddressPrefix should not overlap with each other and GatewaySubnet not overlap the existed Subnet in the specific Vnet. You can find correct GatewaySubnet by adding a new subnet in Vnet config (don’t save).

Attach the code URL: https://github.com/tombwu/ConnectAzureVPN/blob/master/Site%20To%20Site/BuildSiteToSiteVPN.ps1