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.


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


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!


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.


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.


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.



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


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