The following PowerShell code can be used to convert a VM's unmanaged disk to a Managed Disk, please note that this will automatically convert all the associated data disks attached to the VM.
$rgName =
"myResourceGroup"
$vmName = "myVM"
Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName -Force
ConvertTo-AzureRmVMManagedDisk -ResourceGroupName $rgName
-VMName $vmName
Start-AzureRmVM -ResourceGroupName $rgName -Name $vmName
|
The process takes some time to complete, mainly because Azure copies the VHD from the Azure Storage Account. However, it is very quick, my 45GB VM was converted in less than 5 minutes. Once the conversion is completed, the VM will start and the lease on the original VHD will be released.
When you convert a VHD to a Managed Disk, the Managed Disk is automatically labelled the same name as the VM. It discounts the name of the source VHD from the storage account.