Create and upload a Windows Server VHD to Azure

This article shows you how to upload your own generalized VM image as a virtual hard disk (VHD) so you can use it to create virtual machines. For more details about disks and VHDs in Microsoft Azure, see About Disks and VHDs for Virtual Machines.


Azure has two different deployment models for creating and working with resources: Resource Manager and Classic. This article covers using the Classic deployment model. Microsoft recommends that most new deployments use the Resource Manager model. You can also upload a virtual machine using the Resource Manager model.

Starting November 15, 2017, Virtual Machines will be available only in the Azure portal. Access from the classic portal will no longer be supported.


This article assumes you have:

  • An Azure subscription - If you don't have one, you can open an Azure account for free.
  • Microsoft Azure PowerShell - You have the Microsoft Azure PowerShell module installed and configured to use your subscription.
  • A .VHD file - supported Windows operating system stored in a .vhd file and attached to a virtual machine. Check to see if the server roles running on the VHD are supported by Sysprep. For more information, see Sysprep Support for Server Roles.


    The VHDX format is not supported in Microsoft Azure. You can convert the disk to VHD format using Hyper-V Manager or the Convert-VHD cmdlet. For details, see this blogpost.

Step 1: Prep the VHD

Before you upload the VHD to Azure, it needs to be generalized by using the Sysprep tool. This prepares the VHD to be used as an image. For details about Sysprep, see How to Use Sysprep: An Introduction. Back up the VM before running Sysprep.

From the virtual machine that the operating system was installed to, complete the following procedure:

  1. Sign in to the operating system.
  2. Open a command prompt window as an administrator. Change the directory to %windir%\system32\sysprep, and then run sysprep.exe.

    Open a Command Prompt window

  3. The System Preparation Tool dialog box appears.

    Start Sysprep

  4. In the System Preparation Tool, select Enter System Out of Box Experience (OOBE) and make sure that Generalize is checked.
  5. In Shutdown Options, select Shutdown.
  6. Click OK.

Step 2: Create a storage account and a container

You need a storage account in Azure so you have a place to upload the .vhd file. This step shows you how to create an account, or get the info you need from an existing account. Replace the variables in ‹ brackets › with your own information.

  1. Login

  2. Set your Azure subscription.

    Select-AzureSubscription -SubscriptionName <SubscriptionName>
  3. Create a new storage account. The name of the storage account should be unique, 3-24 characters. The name can be any combination of letters and numbers. You also need to specify a location like "East US"

    New-AzureStorageAccount –StorageAccountName <StorageAccountName> -Location <Location>
  4. Set the new storage account as the default.

    Set-AzureSubscription -CurrentStorageAccountName <StorageAccountName> -SubscriptionName <SubscriptionName>
  5. Create a new container.

    New-AzureStorageContainer -Name <ContainerName> -Permission Off

Step 3: Upload the .vhd file

Use the Add-AzureVhd to upload the VHD.

From the Azure PowerShell window you used in the previous step, type the following command and replace the variables in ‹ brackets › with your own information.

Add-AzureVhd -Destination "https://<StorageAccountName><ContainerName>/<vhdName>.vhd" -LocalFilePath <LocalPathtoVHDFile>

Step 4: Add the image to your list of custom images

Use the Add-AzureVMImage cmdlet to add the image to the list of your custom images.

Add-AzureVMImage -ImageName <ImageName> -MediaLocation "https://<StorageAccountName><ContainerName>/<vhdName>.vhd" -OS "Windows"

Next steps

You can now create a custom VM using the image you uploaded.