guide · static export
PC · storage

Mount a VHDX as a Permanent Drive Letter

A virtual hard disk is a portable encrypted container, a backup target or a test sandbox. Mount it with Mount-DiskImage, give it a letter and make it attach itself at every logon.

by@guidox updated:10/31/26 time:25 min level:Intermediate tested on:Windows 11 24H2 works on:Windows 10, Windows 11, Windows Server 2019 tools:PowerShell as administrator, Disk Management
TL;DR

Create the file with **New-VHD** or **diskpart**, attach it with **Mount-DiskImage**, partition it once, then schedule **Mount-DiskImage** at logon so the letter appears before you open Explorer.

Before you start

Requirements

  • Admin rights
  • Free space for the container file
  • 25 minutes
Step by step

Instructions

01

Create the container file

**New-VHD** makes a dynamically expanding file, so a 200 GB disk occupies only what it stores. Fixed sizing is faster but reserves the full size on day one.

New-Item -ItemType Directory D:\Vault -Force | Out-Null
New-VHD -Path D:\Vault\data.vhdx -SizeBytes 200GB -Dynamic
Get-VHD -Path D:\Vault\data.vhdx | Select-Object Path,Size,FileSize,Attached
02

Attach it and find its disk number

**Mount-DiskImage** attaches the file as a real disk. The disk is offline until it is brought online, and its number is what every later diskpart command needs.

Mount-DiskImage -ImagePath D:\Vault\data.vhdx
Get-DiskImage -ImagePath D:\Vault\data.vhdx | Get-Disk | Select-Object Number,OperationalStatus,PartitionStyle
Get-Disk | Where-Object Location -like '*data.vhdx*' | Select-Object Number,FriendlyName
03

Partition and format it once

This is the same initialisation a physical drive needs. After the format, Windows remembers the volume and the letter is reused on every attach.

Initialize-Disk -Number 3 -PartitionStyle GPT
New-Partition -DiskNumber 3 -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel Vault -Confirm:$false
Get-Volume -FileSystemLabel Vault | Select-Object DriveLetter,Size,SizeRemaining
⚠ warningConfirm the disk number from step 2 before running Initialize-Disk. The wrong number wipes a real drive.
04

Make the letter stick at logon

A mounted VHDX disappears at reboot. A logon task that runs **Mount-DiskImage** restores it silently, and the volume keeps the letter it was given.

$a = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -Command "Mount-DiskImage -ImagePath D:\Vault\data.vhdx -NoDriveLetter:$false"'
$t = New-ScheduledTaskTrigger -AtLogOn
Register-ScheduledTask -TaskName 'Mount Vault VHDX' -Action $a -Trigger $t -RunLevel Highest -User $env:USERNAME
Get-ScheduledTask -TaskName 'Mount Vault VHDX' | Select-Object TaskName,State
05

Verify the mount survives a reboot

Reboot, sign in, then read the volume and the image state. **Attached** must be true and the letter must be the one from the format step.

Get-DiskImage -ImagePath D:\Vault\data.vhdx | Select-Object Attached,DevicePath
Get-Volume | Where-Object FileSystemLabel -eq 'Vault' | Select-Object DriveLetter,HealthStatus
Test-Path V:\
06

Detach it cleanly when you travel

**Dismount-DiskImage** flushes the volume and closes the file, which is what makes the container safe to copy. Unplugging the drive it sits on without this step is how VHDX files get corrupted.

Dismount-DiskImage -ImagePath D:\Vault\data.vhdx
Get-DiskImage -ImagePath D:\Vault\data.vhdx | Select-Object Attached
Get-Item D:\Vault\data.vhdx | Select-Object Name,Length,LastWriteTime
tipCopy the file only while it is detached. A VHDX in use is locked and a raw copy of it can be inconsistent.
Troubleshooting

Common issues

The disk stays offline after mounting

Bring it online with Set-Disk -Number 3 -IsOffline $false, then check OperationalStatus before partitioning.

The letter changed after a reboot

Another volume grabbed the letter first. Assign a letter at the high end with Set-Partition -DriveLetter, or set it in the disk's mount manager entry.

The logon task runs but nothing appears

The task must run in the user session with highest privileges. Check LastTaskResult with Get-ScheduledTaskInfo and the task history for an access-denied entry.

Dismount fails with a sharing violation

A file or a program still uses the volume. Close it, or run Get-Process and stop the handle holder before retrying.

FAQ

Frequently asked

Is this the same as booting Windows from a VHD?

No. Booting from a VHD makes the container the system disk and needs a boot entry. Here the file is just a data volume that appears as a normal drive.

Can the container be encrypted?

Yes, either with a drive encryption tool on the host volume that holds the file, or by enabling encryption inside the mounted volume itself.

How large can the file get?

Up to 64 TB on NTFS, but keep the dynamic file well below the free space of the host drive so it never fails to expand.

How to undo this

Unregister the logon task with Unregister-ScheduledTask -TaskName 'Mount Vault VHDX' -Confirm:$false, dismount the image, then delete the VHDX file. Any data stored on the volume goes with it.

Changelog · 1 entry
  1. 2026-10-31
    First version
Interactive version: checklist, feedback, related guides →

Free · no account needed · tracks your progress