atlas by clearpeople

Migrating a Hyper-V Virtual Machine to Azure

11 January 2017
  

In the last few weeks I’ve been working on a study of how easy or hard it would be to migrate a whole SharePoint farm built on Hyper-V Virtual Machines to Azure IaaS. I must begin with saying that I’m not an infrastructure expert, as in my daily work I’m focused on SharePoint development stuff, but I’ve played a bit with Azure in the past, and specially, managing Azure from PowerShell scripts, as I’m a PowerShell Script lover.

 

So, my first attempt/test, was trying to move just an all-in-one SharePoint Virtual Machine used for development, and it was quite easy. Below you can see the steps I followed. Bear in mind that we are using the cmdlets related with Azure Resource Manager modules which corresponds to portal.azure.com.

 

Step 1 - Logging into Azure:
Login-AzureRmAccount

 

Step 2 - The AzureRM-related cmdlets needs to be set with which Azure subscription we are going to operate, in case we have more than one. To do so, we need to select the correct one running the following statement:
Get-AzureRmSubscription -SubscriptionName "Visual Studio Enterprise" | Select-AzureRmSubscription

Step 3 - Next step is to upload the VM to Azure as a blob. Before being able to do that, we need to know that Azure IaaS only supports VHD files, not VHDX files. So, I had to convert my VHDX Virtual Machine to VHD. Fortunately, there is a pretty straightforward cmdlet to do that. It can take some time, depending on the size of the VM.
Convert-VHD -Path “C:\SP2013Dev.vhdx” -Destination-Path “C:\SP2013Dev.vhd”

Step 4 - Once that we have our VM as a VHD file, we are ready to upload it to Azure as a BLOB. Before doing that, we need to know which Resource Group we are going to use, plus the Storage Account container where we are going to place the BLOB.
$resourceGroupName = "cmzg-resource-group"
$sourceVhd = "C:\SP2013Dev.vhd "
$destinationVhd = "https://cmzg.blob.core.windows.net/vhds/SP2013Dev.vhd"
Add-AzureRmVhd -LocalFilePath $sourceVHD -Destination $destinationVHD
-ResourceGroupName $resourceGroupName -NumberOfUploaderThreads 5


Again, this can take some time depending on the file size, and also your broadwidth. Once the uploading is completed, you will see the BLOB file in your Storage Account.

Step 5 - The next and final step is to create a new VM based on our just uploaded VHD file. This step, involves in turn other steps that I’m going to describe. At the end, creating an Azure VM though PowerShell feels like creating different pieces of a puzzle to finally mix them all together.

a. Network Interface and Public IP address
$virtualNetworkName = "cmzg-virtual-network"
$locationName = "North Europe"
$virtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Name $virtualNetworkName


$publicIp = New-AzureRmPublicIpAddress -Name "SP2013Dev-IP" -ResourceGroupName $ResourceGroupName -Location $locationName -AllocationMethod Dynamic

$networkInterface = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName -Name "SP2013Dev-NIC" -Location $locationName -SubnetId $virtualNetwork.Subnets[0].Id -PublicIpAddressId $publicIp.Id


b. Finally, we can start creating the VM, but first we need to know what VMSize we are going to use. We can list all the available options:
Get-AzureRmVMSize $locationName | Out-GridView

c. Now we are ready to configure the VM using the New-AzureRMVMConfig cmdlet:
$vmConfig = New-AzureRmVMConfig -VMName "SP2013Dev-Config" -VMSize "Standard_DS1"
$vmConfig = Set-AzureRmVMOSDisk -VM $vmConfig -Name " SP2013Dev-OSDisk" -VhdUri $destinationVhd -CreateOption Attach -Windows
$vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $networkInterface.Id


d. And now that we have all the pieces, last step is just to create the virtual machine. This operation can take a while, but you can see the progress through the Azure Portal.
$myVM = New-AzureRmVM -VM $vmConfig -Location $locationName -ResourceGroupName $resourceGroupName

And that’s all! Just wait a few minutes, and you should be able to access to your virtual machine using the same domain and account you were using on-premise.

Do you want to know more about Microsoft Azure or do you have any other questions? Please feel free to get in touch with us.

Author bio

ClearPeople

ClearPeople

Get our latest posts in your inbox