Which PowerShell Cmdlet Uploads a Generalized VHD Image to Azure?
Short answer
B Add-AzVhd uploads the generalized on-premises VM VHD into Azure blob storage so the image is available when creating new Azure VMs.
Question
You plan to deploy several new virtual machines (VMs) in Azure. The VMs will have the same operating system and custom software requirements.
You configure a reference VM in the on-premise virtual environment. You then generalize the VM to create an image.
You need to upload the image to Azure to ensure that it is available for selection when you create the new Azure VMs.
Which PowerShell cmdlets should you use?
Key Takeaways
The task is an image upload from an on-premises VHD, and the tested trap is confusing Add-AzVhd with image-authoring cmdlets like New-AzImage or nonexistent cmdlets such as Add-AzImage.
This AZ-104 question tests how to move a generalized on-premises VM image into Azure so it can be reused for multiple new virtual machines. The correct cmdlet is Add-AzVhd, which uploads the virtual hard disk file to Azure storage where it can then be used as a VM image source.
Common mistake: The most common wrong pick is C (Add-AzImage) — no such cmdlet exists; Azure Image creation uses New-AzImage with Add-AzImageDataDisk used only to attach data disks to an in-memory image object. Learners also confuse uploading with Add-AzVM, which provisions the VM itself.
Expert Analysis
Why the Answer Is Correct
After you generalize an on-premises VM (Sysprep) and export it as a VHD, the file must be physically transferred into Azure blob storage before any Azure-side image resource can reference it. The Az.Compute module's Add-AzVhd cmdlet performs exactly this step, following the documented patternAdd-AzVhd -ResourceGroupName $rg -Destination $blobUrl -LocalFilePath.\image.vhd. Only after the VHD lands in blob storage do the image-creation steps (New-AzImage referencing that blob URI) apply, so B is the cmdlet for this specific 'upload' task. Multiple community contributors confirmed this, including Chi1987, who posted the working command syntax, and aut0pil0t, who noted the question 'focuses on the "upload" where we actually upload a VHD.'Why the Other Options Are Wrong
A. Add-AzVM does not exist as the provisioning cmdlet for this flow — VMs are created with New-AzVM — and in any case provisioning a VM is not the same as uploading an image. C. Add-AzImage is not a real Az module cmdlet; the actual image-authoring cmdlet is New-AzImage, so choosing C selects a cmdlet that will fail at the prompt. D. Add-AzImageDataDisk exists, but as jersonmartinez-style commentary and NaoVaz both explain, it 'Adds a data disk to an image object' — an in-memory step that presupposes an image object already exists, not the upload step asked about here. One dissenting comment argued C because Add-AzVhd 'is not used for creating generalized VM images,' but that misreads the stem: the question asks only for uploading the already-generalized image.Community Comment Notes
NaoVaz (the top-voted comment, 87 likes) systematically eliminated the alternatives, noting that 'Add-AzImage' does not exist and that the real cmdlet is New-AzImage, and settled on Add-AzVhd. Chi1987 supplied the exact working invocation, and ant_man added the mnemonic that 'VHD stands for 'Virtual Hard Disk' - Add-AzVhd.' Damiski argued for C, but that reasoning rests on the non-existent Add-AzImage cmdlet and was contradicted by the rest of the thread; margotfrpp's link, despite claiming otherwise, actually points to the New-AzImage documentation, reinforcing that C is invalid.Official Reference
- https://learn.microsoft.com/en-us/powershell/module/az.compute/add-azvhd
- https://learn.microsoft.com/en-us/azure/virtual-machines/windows/disks-upload-vhd-to-managed-disk-powershell
These links open the official vendor documentation in a new tab.
Exam Strategy
In AZ-104 image questions, separate the workflow into three stages — generalize/upload (Add-AzVhd), create the managed image resource (New-AzImage), then deploy (New-AzVM) — and pick the cmdlet matching the stage named in the stem. If an option names a cmdlet you have never seen in Microsoft Learn module docs, treat it as a distractor rather than assuming it exists.
Frequently Asked Questions
Why is Add-AzImage wrong when the question says "upload the image"?
What is the Add-AzVhd command syntax for uploading a generalized VHD?
Discussion 69 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 30 of 69
Show 25 more comments
-
Damiski 👍 5To upload a generalized virtual machine image to Azure for use in creating new Azure VMs, you should use the following PowerShell cmdlet: C. Add-AzImage Here's a brief explanation of each option: A.
Add-AzVMis used to create a new Azure virtual machine, not to upload images. B.Add-AzVhdis used to upload a virtual hard disk (VHD) to Azure. It's not used for creating generalized VM images. C.Add-AzImageis specifically designed for uploading generalized VM images to Azure. This is the cmdlet you should use for your scenario. D.Add-AzImageDataDiskis used to add a data disk to an existing Azure virtual machine, not for uploading generalized images. So, in your case, you should useAdd-AzImageto upload your generalized VM image to Azure so that it can be used to create new Azure VMs. -
aut0pil0t 👍 5 Answered BThis focuses on the "upload" where we actually upload a VHD. What's referred as "image" here is the generalised disk, not the Azure image. So, to upload a disk to create an Azure image later, answer is B. https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-upload-vhd-to-managed-disk-powershell
-
ant_man 👍 5 Answered BVHD stands for 'Virtual Hard Disk' - Add-AzVhd
-
bcristella 👍 4B is correct answer. This article walks you through using PowerShell to upload a VHD of a generalized VM to Azure, create an image from the VHD, and create a new VM from that image. You can upload a VHD exported from an on-premises virtualization tool or from another cloud. Using Managed Disks for the new VM simplifies the VM management and provides better availability when the VM is placed in an availability set. https://docs.microsoft.com/en-us/azure/virtual-machines/windows/upload-generalized-managed
-
754a 👍 4Because add-azimage isn't a command, new-azimage is to create an image and isn't an option, but the question asks about "upload" image. Answer is B: https://docs.microsoft.com/en-us/powershell/module/az.compute/add-azvhd?view=azps-6.5.0
-
sk1803 👍 4Answer: B I would like to answer New-AzImage, but that is not an option. In order to create the image, I do have to have my VHD uploaded to azure though. I would use Add-AzVhd for that.
-
margotfrpp 👍 4this command exist " Add-AzImage" https://learn.microsoft.com/en-us/powershell/module/az.compute/new-azimage?view=azps-9.6.0
-
BowSec 👍 3 Answered CTo upload a generalized virtual machine (VM) image to Azure for use in creating new Azure VMs, the PowerShell cmdlets that should be used are: 1. Sysprep the reference VM in the on-premises virtual environment to generalize the image. 2. Use the Export-AzVM cmdlet to export the generalized VM to a .zip file. 3. Use the New-AzStorageAccount cmdlet to create an Azure storage account. 4. Use the Set-AzStorageBlobContent cmdlet to upload the .zip file to the Azure storage account. 5. Use the Add-AzImage cmdlet to create a new custom image from the uploaded .zip file. Therefore, the correct answer is C. Add-AzImage. Note that Add-AzVM, Add-AzVhd, and Add-AzImageDataDisk are not the appropriate cmdlets for uploading a generalized VM image to Azure. Add-AzVM is used for creating new virtual machines in Azure, while Add-AzVhd and Add-AzImageDataDisk are used for attaching virtual hard disks and data disks to virtual machines.
-
lokii9980 👍 3The correct PowerShell cmdlet to upload the image to Azure is C. Add-AzImage. Explanation: To upload the generalized VM image to Azure and make it available for selection when creating new VMs, you need to use the Add-AzImage cmdlet. This cmdlet creates a new Azure image from a generalized VM, managed disk, or VHD file. The Add-AzVM cmdlet is used to create a new Azure virtual machine. The Add-AzVhd cmdlet is used to upload a virtual hard disk (VHD) file to Azure storage. The Add-AzImageDataDisk cmdlet is used to add a new data disk to an existing Azure virtual machine. Therefore, the correct PowerShell cmdlet to use in this scenario is C. Add-AzImage.
-
Thomas_M 👍 3 Answered BTo upload a generalized VM image to Azure and make it available for creating new VMs, you would use a combination of the following PowerShell cmdlets: Add-AzVhd: This cmdlet uploads the generalized VHD file (your image) to an Azure storage account. Add-AzImage: This cmdlet creates a managed image from the uploaded VHD file, making it available for creating new Azure VMs.
-
Sahar_A 👍 3 Answered CB. Add-AzVhd to upload a generalized VHD file to Azure C. Add-AzImage to register the uploaded VHD as a custom image in Azure, making it selectable for new VM creation. So B is the first step, but C is what makes it available for selection
-
Snownoodles 👍 3 Answered BMicrosoft doesn't recommend to use 'add-advhd' anymore, use azcopy: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-upload-vhd-to-managed-disk-powershell
-
lemoniazure 👍 3Answer B: 1.Prepare vhd 2.upload vhd 3.create image by using vhd 4.create vm by using image
-
TonyH20 👍 2 Answered CAI Mode All Videos Images Shopping Short videos Forums Web News Books Maps Flights Finance 3 sites New-AzImage (Az.Compute) | Microsoft Learn Learn Microsoft Add-AzImageDataDisk (Az.Compute) | Microsoft Learn Learn Microsoft Create a legacy managed image of a generalized VM in Azure Azure.cn Add-AzImageDataDisk (Az.Compute) | Microsoft Learn Learn Microsoft Based on the search results, it seems there's a slight confusion about the exact cmdlet. The correct cmdlet for adding an image in Azure PowerShell is actually New-AzImage, and you might use Add-AzImageDataDisk to add data disks to an image object. Here's how these cmdlets relate to managing images in Azure, according to the Microsoft Learn documentation: New-AzImage: This cmdlet is used to create a new Azure image. This is the primary cmdlet for creating a custom VM image in Azure from a generalized VM or a snapshot.
-
Manny123456 👍 2https://learn.microsoft.com/en-us/azure/devtest-labs/devtest-lab-upload-vhd-using-powershell Check upload a VHD file process: To upload a VHD file by using PowerShell: In a text editor, paste the generated PowerShell script you copied from the Azure portal. Modify the -LocalFilePath parameter of the Add-AZVHD cmdlet to point to the location of the VHD file you want to upload. At a PowerShell command prompt, run the Add-AZVHD cmdlet with the modified -LocalFilePath parameter. The process of uploading a VHD file might be lengthy depending on the size of the VHD file and your connection speed. The correct answer is Add-AzVHD
-
0a92195 👍 2 Answered CC. Add-AzImage Explanation: Since you generalized the VM to create an image, you need to upload it to Azure as a managed image. Add-AzImage is the PowerShell cmdlet used to add a VM image to Azure, making it available for creating new VMs. Why Not the Other Options? A. Add-AzVM → This is used to create a VM, not to upload an image. B. Add-AzVhd → Used for uploading a VHD file, but does not create an image from it. D. Add-AzImageDataDisk → Used to add a data disk, not a VM image.
-
arkadius 👍 2 Answered B$vhdSizeBytes = (Get-Item "<fullFilePathHere>").length . $diskconfig = New-AzDiskConfig -SkuName 'Standard_LRS' -OsType 'Windows' -UploadSizeInBytes $vhdSizeBytes -Location '<yourregion>' -CreateOption 'Upload' . New-AzDisk -ResourceGroupName '<yourresourcegroupname>' -DiskName '<yourdiskname>' -Disk $diskconfig . https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-upload-vhd-to-managed-disk-powershell
-
koenigParas2324 👍 2 Answered CThe correct PowerShell cmdlet to use for uploading the generalized VM image to Azure is C. Add-AzImage. This cmdlet is used to create a new image in Azure. After generalizing the VM to create an image, you can use the Add-AzImage cmdlet to upload the image to Azure, ensuring that it is available for selection when creating new Azure VMs
-
karmaah 👍 2Correction. Assuming Image is already created as per the question, Option B is the only option to upload image files which will be having .vhd ( Image Files ). eg : Add-AzVhd -Destination "http://contosoaccount.blob.core.windows.net/vhdstore/win7baseimage.vhd" -LocalFilePath "C:\vhd\Win7Image.vhd" -Overwrite
-
y_dev 👍 2example command : Add-AzVhd -Destination "http://contosoaccount.blob.core.windows.net/vhdstore/win7baseimage.vhd?st=2013-01 -09T22%3A15%3A49Z&se=2013-01-09T23%3A10%3A49Z&sr=b&sp=w&sig=13T9Ow%2FRJAMmhfO%2FaP3HhKKJ6AY093SmveO SIV4%2FR7w%3D" -LocalFilePath "C:\vhd\win7baseimage.vhd"
-
Andre369 👍 2 Answered CC. Add-AzImage The Add-AzImage cmdlet is used to create a new image in Azure from an existing generalized VM image. This cmdlet allows you to upload the image to Azure and make it available for selection when creating new VMs.
-
Yuraq 👍 2Add-AzVhd Uploads a virtual hard disk from an on-premises machine to Azure (managed disk or blob). https://learn.microsoft.com/en-us/powershell/module/az.compute/add-azvhd?view=azps-10.4.1&viewFallbackFrom=azps-7.3.0
-
elishlomo 👍 2 Answered BB. The Add-AzVhd cmdlet uploads an on-premise virtual hard disk to a managed disk or a blob storage account. https://docs.microsoft.com/en-us/powershell/module/az.compute/add-azvhd?view=azps-7.0.0
-
Empel 👍 2From your own link "Generally, you should use Add-AzVHD. However, if you need to upload a VHD that is larger than 50 GiB, consider uploading the VHD manually with AzCopy"
-
Oniseialexandru 👍 2 Answered CC, just read carefully the question the intention is not to migrate is to create a custom image that will be available in the store when creating a new vm.
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All AZ-104 Questions
Access 100 questions with complete answers and detailed explanations.
View Full AZ-104 Practice Test →
New-AzImage. That's different.