Search This Blog

Thursday, December 15, 2016

Step-by-step: How to create a virtual machine from VHD in Azure Portal

You cannot create a new VM in Azure portal from Azure web portal, so the only way at this point is to use Powershell. Here are steps to create a working VM from existing VHD:

1. Upload the VHD to Azure using Azure Storage Explorer or other tool. Make sure that it really is VHD format, upload it as Page Blob and the OS in VHD has been configured to obtain IP address from DHCP.

2. Start Powershell.
3. Login-AzureRmAccount to login to Azure tenant.
4. Use these commands
$resourceGroupName = "ResourceGroupName"

$virtualNetworkName = "VirtualNetworkName"

$virtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Name $virtualNetworkName

5. Create a Network interface in Azure Portal
6. Use these Powershell commands
$networkInterface = Get-AzureRmNetworkInterface -Name "NetworkInterfaceName" -resourcegroupname $resourceGroupName

$vmConfig = New-AzureRmVMConfig -VMName "VMName" -VMSize "Standard_D1_v2"

$vmConfig = Set-AzureRmVMOSDisk -VM $vmConfig -Name "VirtualDiskName" -VhdUri UploadedVHDUrl -CreateOption Attach -Windows

$vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $networkInterface.Id

$vm = New-AzureRmVM -VM $vmConfig -Location $locationName -ResourceGroupName $resourceGroupName

You can obtain VHD URL from Azure Storage Explorer when you right-click onto VHD.
After you execute the last command it will take a while to create the VM.

No comments:

Post a Comment