How to Mount a VHDX Virtual Disk File using PowerShell

Managing Virtual Hard Disks

In modern Windows environments, especially those utilizing Hyper-V virtualization or Azure, system administrators frequently work with VHD and VHDX files. A VHDX file is simply a virtual hard disk—a single file that acts as an entire physical hard drive, containing its own partitions, filesystems, and operating system.

If a virtual machine crashes and fails to boot, a system administrator must extract critical data (like a SQL database file) from the offline VHDX file. While you can open the graphical Disk Management tool (diskmgmt.msc) and navigate through multiple menus to manually attach the virtual disk, PowerShell provides a dedicated module to mount these files instantly, making it ideal for automated backup verification scripts.

Using the Mount-VHD Cmdlet

The cmdlet required to interact with virtual disks is Mount-VHD. This command is part of the Hyper-V module. If you are running this on a standard Windows 11 workstation, you must ensure the Hyper-V Management Tools feature is enabled in the Windows Settings.

Because mounting a disk alters the core operating system hardware abstraction layer, you must run PowerShell with elevated Administrator privileges.

To instantly mount a virtual disk located on an external backup drive, execute the following command:

Mount-VHD -Path "E:\Backups\Server01_Data.vhdx"

The command executes silently. The Windows operating system immediately reads the file, spins up a virtual disk controller, and attaches the volume to the host machine.

Assigning Drive Letters

When you run Mount-VHD, Windows attaches the disk, but it does not always automatically assign it a drive letter. If you open File Explorer, the drive might be invisible.

To mount the VHDX file and immediately assign it the next available drive letter (e.g., the F: drive), you must pipe the output of the mount command into the Get-Disk and Get-Partition cmdlets.

Mount-VHD -Path "E:\Backups\Server01_Data.vhdx" -PassThru | Get-Disk | Get-Partition | Set-Partition -NewDriveLetter F

This powerful one-liner mounts the file, identifies the specific disk number it was assigned, locates its primary partition, and forces Windows to assign it the F: letter. You can now browse the files immediately using File Explorer or the terminal.

Mounting as Read-Only

If you are performing digital forensics on a compromised virtual machine, or if you simply want to extract a file from a production backup without risking accidental modification, you must mount the drive in a protected state.

You can append the -ReadOnly flag to completely lock the virtual disk.

Mount-VHD -Path "E:\Backups\Server01_Data.vhdx" -ReadOnly

The drive will mount successfully, but any attempt to modify a file or copy new data onto the F: drive will result in a hard “Access Denied / Write Protected” error from the operating system.

Dismounting the Drive

When you are finished recovering your files, you must safely detach the virtual disk to prevent data corruption in the VHDX file. Do not simply unplug the external hard drive.

Use the Dismount-VHD cmdlet:

Dismount-VHD -Path "E:\Backups\Server01_Data.vhdx"

The virtual disk is instantly ejected, and the file is safely closed.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.