How to get the VHD of an Azure managed disk?

2019-04-15 10:43发布

问题:

I have created a VM with a managed disk. Managed disks are no longer stored into the blob storage by default. Problem is that I now need the vhd file of the osdisk, but I am unable to find a proper way to retrieve it.

The only method I found is to open the disk in the azure portal and press Export to create a download link to the vhd file. This method is undesired.

回答1:

Make sure your AzureRM Powershell Module is up to date:

Install-Module AzureRM -allowclobber -force

Your Set-AzureRMVMOSDisk command should now have -ManagedDiskID. Just enter the resource ID for the managed disk and it should work.

Example

$NewVM = New-AzureRMVMConfig -VMName VMName - VMSize "Standard_A1_V2"
Set-AzureRMVMOSDisk -VM $NewVM -Name "DiskName" -CreateOption Attach -Caching ReadWrite -Windows -ManagedDiskID "ManagedDiskResourceID"
New-AzureRmVM -ResourceGroupName "ResourceGroupName" -VM $NewVM -Location CanadaEast


回答2:

For managed disks you do not use a vhd. Rather, for the disk section, you use a template like this

"osDisk": {
    "osType": "Linux",
    "name": "[parameters('VMName')]",
    "createOption": "FromImage",
    "caching": "ReadWrite",
    "managedDisk": {
        "id": "ManagedDiskID"
    }
}

You reference the disk by managed disk ID rather than uri