We have been moving resources from ESXi to Hyper-V to Azure. ESXi to Hyper-V is done via the Microsoft Virtual Machine Converter (MVMC). Here is the Checklist/Script/Procedure I have been using to get Hyper-V to Azure.
- Once machine is in Hyper-V, make sure the VMs HDs are VHD and not VHDX
- Make sure DHCP is set on the VM
- Make sure RDP is enabled (ours is set via group policy)
- Power down VM
- Run the PowerShell below to add the HD (Add-AzurermVhd), and create a new VM in Azure:
Login-AzureRmAccount $VMName="NAMEOFMACHINE" $DestinationVMSize="Standard_A1" $DestinationAvailabilitySet="AvailabilitySetName" $PrivateIpAddress="192.168.5.55" $ResourceGroupName="YourResourceGroup" $DestinationNetworkName="YourNetwork" $DestinationNetworkSubnet="YourLanSubnet" $Location="East US2" $OSType="Windows" [switch]$DataDisk=$false $SourceSystemLocalFilePath="C:\PathToYour\VHDs\$($VMName)-System.vhd" $SourceDataLocalFilePath="C:\PathToYour\VHDs\$($VMName)-Data.vhd" $DestinationStorageAccountName="yourstorageaccount" $DestinationSystemDiskUri= "http://$DestinationStorageAccountName.blob.core.windows.net/vhds/$VMName-System.vhd" $DestinationDataDiskUri= "http://$DestinationStorageAccountName.blob.core.windows.net/vhds/$VMName-Data.vhd" $DestinationSystemDiskName="$($VMNAME)_SYSTEM.vhd" $DestinationDataDiskName="$($VMNAME)_DATA01.vhd" Add-AzurermVhd -Destination $DestinationSystemDiskUri -LocalFilePath $SourceSystemLocalFilePath -ResourceGroupName $ResourceGroupName if ($DataDisk){ Add-AzurermVhd -Destination $DestinationDataDiskUri -LocalFilePath $SourceDataLocalFilePath -ResourceGroupName $ResourceGroupName } #region Build New VM $DestinationVM = New-AzureRmVMConfig -vmName $vmName -vmSize $DestinationVMSize -AvailabilitySetId $(Get-AzureRmAvailabilitySet -ResourceGroupName $ResourceGroupName -Name $DestinationAvailabilitySet).Id $nicName="$($VMName)_NIC01" $vnet = Get-AzureRmVirtualNetwork -Name $DestinationNetworkName -ResourceGroupName $ResourceGroupName $subnet = $vnet.Subnets | where {$_.Name -eq $DestinationNetworkSubnet} $nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $Subnet.Id -PrivateIpAddress $PrivateIpAddress $DestinationVM = Add-AzureRmVMNetworkInterface -VM $DestinationVM -Id $nic.Id $DestinationSystemDiskUri = $DestinationSystemDiskUri $DestinationDataDiskUri = $DestinationDataDiskUri If ($OSType -eq "Windows"){ $DestinationVM = Set-AzureRmVMOSDisk -VM $DestinationVM -Name $DestinationSystemDiskName -VhdUri $DestinationSystemDiskUri -Windows -CreateOption attach if ($DataDisk){ $DestinationVM = Add-AzureRmVMDataDisk -VM $DestinationVM -Name $DestinationDataDiskName -VhdUri $DestinationDataDiskUri -CreateOption attach -DiskSizeInGB $DatDiskSize } } New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $Location -VM $DestinationVM
The most important part is to use “-attach” with “Set-AzureRmVMOSDisk”
Hope that helps someone.
No comments yet.