Skip navigation
John Savill'ss FAQs on IT Pro Today Hero

Savill's FAQs: Using and managing VHD files in Microsoft Azure

Three times a week, John Savill tackles your most pressing IT questions. Today learn about handling VHD images in Microsoft's Azure cloud service with PowerShell.

Three times a week (Monday/Wednesday/Friday), John Savill tackles your most pressing IT questions.

Read through the FAQ archives, or send him your questions via email.

Today: Uploading VHD files to Azure, creating new images in Azure using uploaded VHDs, and removing custom images in Azure using PowerShell

Q. I'm uploading VHD files to Azure however I'm unable to use them in Azure, it says its not a valid VHD file.

A. The best way to upload your own VHD file to Azure is to use PowerShell. Install the AzureRM module on your machine, login to Azure, select your subscription then upload the image. Below are the commands I use to upload my images.



Select-AzureRmSubscription -SubscriptionId "b6e3.....12c9e"

$rgImgName = "RGSCUSPOC"
$urlOfUploadedImageVhd = ""
Add-AzureRmVhd -ResourceGroupName $rgImgName -Destination $urlOfUploadedImageVhd `
-LocalFilePath "S:\OS Images\PE\1709\WinPEPS.vhd"

This ensures the VHD file is in the correct format once copied up.

Q. How can I easily create a new image in Azure for a VHD I have uploaded?

A. One of the great things about managed disks (where the storage account is abstracted away and the disk becomes a true resource) is the ability to create your own custom images which used to be possible with Azure Service Manager (ASM). Once you have uploaded your own VHD to Azure you can create an image as follows:

$location = "South Central US"
$imageName = "WinPEImage"

$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsType Windows -OsState Generalized -BlobUri $urlOfUploadedImageVhd
$image = New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgImgName -Image $imageConfig

Note I have configured the image as Windows and confirmed it has been generalized, i.e. I have ran SYSPREP so its ready to be duplicated. If you put this with the previous FAQ I upload VHD files and then create images from them.

Q. How can I delete a custom image in Azure?

A. To delete a custom image use the Remove-AzureRmImage cmdlet, for example:

Remove-AzureRmImage -ImageName $imageName -ResourceGroupName $rgImgName

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.