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.
December 23, 2017
![John Savill'ss FAQs on IT Pro Today Hero John Savill'ss FAQs on IT Pro Today Hero](https://eu-images.contentstack.com/v3/assets/blt07f68461ccd75245/blt4f4dff0d1de7f357/66194a27fe93598637dd259d/savillfaqhero1_1_2_4.jpg?width=1280&auto=webp&quality=95&format=jpg&disable=upscale)
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.
Login-AzureRmAccount
Get-AzureRmSubscription
Select-AzureRmSubscription -SubscriptionId "b6e3.....12c9e"
$rgImgName = "RGSCUSPOC"
$urlOfUploadedImageVhd = "https://savpoc.blob.core.windows.net/poctemplates/WinPEPS.vhd"
Add-AzureRmVhd -ResourceGroupName $rgImgName -Destination $urlOfUploadedImageVhd `
-LocalFilePath "S:OS ImagesPE1709WinPEPS.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
Read more about:
MicrosoftAbout the Author
You May Also Like