Import a VHD from a Storage Account as a Managed Disk

In Azure, unmanaged disks stored as VHD files in a Storage Account are still common in backup, migration, and image-based workflows. However, modern Azure VMs use managed disks. To reuse a VHD, you must first import it as a managed disk, then attach that disk to a VM.

This guide walks through the complete process using Azure PowerShell, explains what each step does, and highlights common pitfalls.

When would you use this approach?

Typical scenarios include:

  • Restoring a VM disk from a VHD backup
  • Migrating legacy unmanaged disks to managed disks
  • Attaching a recovered OS or data disk to another VM for inspection
  • Reusing a golden image stored as a VHD

This process works for both OS disks and data disks, but this example focuses on attaching the disk as a data disk to an existing VM.

Prerequisites

Before starting, make sure you have:

  • An existing Azure VM
  • A VHD file stored in an Azure Storage Account (Blob Storage)
  • Permission to:
    • Read the Storage Account
    • Create managed disks
    • Update the VM
  • Azure PowerShell (Az module) installed and authenticated

High-level process

At a high level, the workflow looks like this:

  1. Identify the VHD in Azure Storage
  2. Create a managed disk by importing the VHD
  3. Retrieve the target VM
  4. Attach the managed disk to the VM
  5. Update the VM configuration

Step 0 — Define variables

Start by defining all required variables. This keeps the script readable and reusable.

$resourceGroup = "<resourcegroup>"
$location = "westeurope"
$vmName = "<vmname>"
$vhdUri = "https://storageurl.blob.core.windows.net/vm001-os-20260208-211100.vhd"
$diskName = "vm001-os-20260208-211100"
$storageAccountName = "<storageaccountname>"
$storageAccountRG = "<resourcegroup>"   # Change if storage account is in another RG

Important notes:

  • The VHD must be a fixed-size VHD, not VHDX
  • The blob does not need to be public
  • The Storage Account and VM can be in different resource groups, but must be in the same subscription

Step 1 — Get the Storage Account

Azure needs the Storage Account ID to authorize the import operation.

$storageAccount = Get-AzStorageAccount `
    -ResourceGroupName $storageAccountRG `
    -Name $storageAccountName

This object contains the Storage Account’s ARM ID, which is required when importing a private VHD.

Step 2 — Select the correct subscription

Always explicitly select the subscription to avoid surprises.

Select-AzSubscription -SubscriptionId <subscriptionid>

This is especially important in automation or multi-tenant environments.

Step 3 — Create the managed disk configuration

Here you tell Azure:

  • Where the disk should live
  • That it should be imported from an existing VHD
  • Which Storage Account hosts the VHD
  • What performance tier to use
$diskConfig = New-AzDiskConfig `
    -Location $location `
    -CreateOption Import `
    -SourceUri $vhdUri `
    -AccountType Premium_LRS `
    -StorageAccountId $storageAccount.Id

Key parameters explained:

ParameterDescription
CreateOption ImportTells Azure this disk is created from an existing VHD
SourceUriFull URI to the VHD blob
StorageAccountIdRequired for private blobs
AccountTypeDisk SKU (Premium_LRS, StandardSSD_LRS, Standard_LRS)

Step 4 — Create the managed disk

Now Azure actually creates the disk resource.

$newDisk = New-AzDisk `
    -ResourceGroupName $resourceGroup `
    -DiskName $diskName `
    -Disk $diskConfig

At this point:

  • The VHD is copied internally by Azure
  • A fully managed disk is created
  • The original VHD remains unchanged

You can now reuse this disk just like any other managed disk.

Step 5 — Retrieve the VM object

To attach a disk, you must modify the VM object in memory.

$vm = Get-AzVM `
    -ResourceGroupName $resourceGroup `
    -Name $vmName

This retrieves the current VM configuration, including existing disks and NICs.

Step 6 — Attach the managed disk to the VM

Now attach the imported disk as a data disk.

$vm = Add-AzVMDataDisk `
    -VM $vm `
    -Name $diskName `
    -ManagedDiskId $newDisk.Id `
    -CreateOption Attach `
    -Lun 0 `
    -Caching ReadWrite

Important considerations:

  • LUN must be unique — If the VM already has data disks, use the next available LUN
  • CreateOption Attach — You’re attaching an existing disk, not creating a new one
  • Caching — Use ReadWrite for most data workloads unless otherwise required

Step 7 — Update the VM

Finally, push the updated configuration back to Azure.

Update-AzVM `
    -ResourceGroupName $resourceGroup `
    -VM $vm

Azure will attach the disk without rebooting the VM in most cases. The disk will now appear inside the guest OS.

Inside the guest OS

After the disk is attached:

Windows:

  • Open Disk Management
  • Bring the disk online
  • Initialize and assign a drive letter if needed

Linux:

  • Use lsblk or fdisk -l
  • Mount the disk manually

Common pitfalls and troubleshooting

Import fails with authorization errors

  • Ensure -StorageAccountId is provided
  • Verify the VHD URI is correct

Disk does not show up in the OS

  • Disk may be offline or uninitialized
  • Check the assigned LUN

Wrong disk performance

  • Disk SKU cannot be changed during import
  • You can resize or change SKU after creation

OS disk vs data disk

  • Attaching an OS disk does not boot automatically
  • OS disk swaps require VM deallocation and a different process

Final thoughts

Importing a VHD into Azure as a managed disk is a clean and supported way to modernize legacy workflows, restore disks, or migrate workloads. Once imported, the disk behaves exactly like any other Azure managed disk — including snapshots, backups, and resizing.