Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Windows 10 / Auto-mount VHD/VHDX File at Startup in Windows

February 20, 2024 Windows 10Windows 11Windows Server 2019

Auto-mount VHD/VHDX File at Startup in Windows

In Windows, you can attach (mount) virtual hard disk files in the VHD and VHDX formats directly from the Disk Management console. Windows administrator can mount a VHD or VHDX image file in the File Explorer and assign a drive letter to it. However, these virtual hard disks must be mounted manually each time Windows is restarted.

In this article, we will configure the task to automatically mount VHD/VHDX files when Windows starts.

  1. Open the Task Scheduler management console (Taskschd.msc);
  2. Create a new Basic Task; Create basic task in Task Scheduler
  3. Set the task name: AutoMount_VHDX_G
  4. For Trigger, select When the computer starts;
  5. Action -> Start a program ;Program/script: C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
    Add argument: -command "Mount-DiskImage -ImagePath C:\vhd\lab_data.vhdx –PassThru | Get-Disk | Get-Partition | Set-Partition -NewDriveLetter G"
    powershell - auto mount VHDX file
    This PowerShell command mounts the C:\vhd\lab_data.vhdx file and assigns the drive letter G: to the first image partition. Learn more about managing partitions and drives with PowerShell.
  6. Open the task properties and specify that it should run as NT AUTHORITY\SYSTEM (Change User or group -> SYSTEM); run task as system
  7. Restart Windows and check to see if the VHDX disk is automatically mounted. Automatically mount .vhdx on Windows startup
You can create a Scheduler task using PowerShell.

If you want to mount the VHDX to a folder instead of a separate drive, change the PowerShell command code as follows:

Mount-DiskImage -ImagePath C:\vhd\lab_data.vhdx –PassThru | Get-Disk | Get-Partition | Add-PartitionAccessPath -AccessPath "C:\LAB"

15 comments
8
Facebook Twitter Google + Pinterest
previous post
Configure Storage Spaces Direct (S2D) on Windows Server
next post
Configuring Kerberos Authentication in Different Browsers

Related Reading

How to Cancel Windows Update Pending Restart Loop

May 6, 2025

View Windows Update History with PowerShell (CMD)

April 30, 2025

Change BIOS from Legacy to UEFI without Reinstalling...

April 21, 2025

Remove ‘Your License isn’t Genuine’ Banner in MS...

April 21, 2025

Uninstalling Windows Updates via CMD/PowerShell

April 18, 2025

15 comments

thunderbold January 23, 2016 - 10:15 am

Simple VHD Manager is portable freeware which helps VHD users simplify some of these operations:
– You can easily create VHD/VHDX files
– You can attach and detach VHD/VHDX/ISO files via drag and drop
– You can permanently attach a virtual hard disk in Windows 10 , Windows 8,1 , Windos 8, Windows 7
– You can easily add and/or remove VHD/VHDX/ISO files to the boot menu
http://www.sordum.org/8705/simple-vhd-manager-v1-1/

Reply
Mitchell Stringer January 1, 2019 - 7:34 pm

As always, answer is in the comments, thank you.

Reply
buddieminecraft February 19, 2019 - 9:02 pm

It broke my computer…

Reply
Treeant34 May 20, 2016 - 12:18 am

Virustotal found a couple of trojans in Simple VHD Manager

Reply
thunderbold July 8, 2016 - 9:16 pm

Yes all of them from China 🙂  

Reply
Ben December 29, 2016 - 4:23 am

Nice Article, thanks

Reply
Herbert Quain January 27, 2017 - 11:45 pm

Exactly what I was looking for; unfortunately it didn’t work for me!
I found that letting the Task Scheduler call diskpart with the added arguments did nothing for some reason: it executes the task on start-up, but without any results.

The work-around: In C:\Scripts I added another file ‘diskpart.cmd’ with the single line

diskpart /s “C:\Scripts\attach_vhd.txt”

In the Actions tab, I then simply called ‘C:\Scripts\diskpart.cmd’, instead, without any arguments.
This fixed the issue, although i have no idea what the problem was.

Reply
Arne February 20, 2017 - 4:14 pm

Thanks to Herbert and you others!
This has been a big problem for me! I did not get it to work, and have spent lot of time trying to solve it. But now it works!

I used a cmd-file “Attach_vhd.cmd” with the contents:
   diskpart / s “C: \ Scripts \ attach_vhd.txt”

The file attach_vhd are as described above:
   select VDisk file = “F: \ imagedisk.vhdx”
   attach VDisk
   assign letter = M

It works! Beware the sign ” that must be correct (Ascii 34), it can maybe be wrong when copying from the web-site.

Reply
Todd November 14, 2017 - 8:16 am

“Beware the sign ” that must be correct (Ascii 34), it can maybe be wrong when copying from the web-site.”

Thank you for this tip! When I copied and pasted my Action argument into Notepad, I could see that the problem was with the incorrect quotation marks. After correcting this everything seems to be working. Finally!

Reply
Zoan March 15, 2017 - 11:38 am

Get rid of the quotes in the argument and this procedure works fine. Should be: / s C: \ Scripts \ attach_vhd.txt with no quotes. Delete the spaces in my argument if you’re copying and pasting . It also helps if you configure for Windows 7, if you’re using 7. And delay the task for one minute while everything else starts up.

Reply
Ivo Pereira March 24, 2017 - 9:44 am

Great article, simple and yet with all the necessary detail.

Thanks a lot, I happened to find this problem just yesterday when I rebooted a client’s machine and a VHDx wasn’t mounted. What a life saver 🙂

Cheers,
Ivo Pereira
Portugal

Reply
Tyler September 12, 2018 - 12:32 pm

Ran into a bunch of issues with this article. Then found this one:
https://angler.wordpress.com/2010/03/11/windows-7-auto-mount-vhds-at-startup/
Worked without any issues at all and a little less complicated

Reply
Jamie Sandell June 17, 2019 - 8:45 am

You’re better off using PowerShell.
Manually mount the VHDX in Disk Management (diskmgmt.msc) and assign it a drive letter and volume label. Once you do this it will remember the drive letter and volume name the next time it is mounted.

Then create a .ps1 file and enter
Mount-DiskImage -ImagePath ‘D:\VHDS\MyVirtualDrive.vhdx’ -StorageType VHDX

amending where necessary for the file name and if it is different file extension such as VHD or ISO

Then create a scheduled task, set the trigger to be at startup. Set the action to run Powershell. In the arguments box add -File “D:\VHDS\AutoMountVHDX.ps1”

Reply
vvdicx March 26, 2024 - 11:43 pm

I need to mount multiple vhd(x) before startup:

Windows11.vhd, ProgramFiles.vhd, Data.vhd

Some solutions(e.g. : windows Task, windows services) are not early enough.

I need to mount multiple vhd(x) as early as possible, because some programs(in ProgramFiles.vhd) are also be executed very early on startup.

—————————————————————————————-

Can i mount multiple vhd(x) by using BcdEdit commandline?such as:

Windows Boot Loader

——————-

identifier {default}

device vhd=[D:]\windows11.vhd

path \Windows\system32\winload.efi

description Windows 11

……

osdevice vhd=[D:]\windows11.vhd

systemroot \Windows

……

otherdevice1 vhd=[D:]\ProgramFiles.vhd

otherdevice2 vhd=[D:]\Data.vhd

otherdevice3 ……

——————————————————————————————

Or are there any other solutions?

Reply
Rosdi November 19, 2024 - 6:05 am

This works nicely on my Windows 11

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD

    March 3, 2025
  • How to Hide (Block) a Specific Windows Update

    February 25, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Booting Windows from GPT Disk on BIOS (non-UEFI) Computer
  • Removable USB Flash Drive as Local HDD in Windows
  • How to increase KMS current count (count is insufficient)
  • How to Disable UAC Prompt for Specific Applications in Windows
  • Managing Printers and Drivers on Windows with PowerShell
  • Managing Printers from the Command Prompt in Windows
  • Using WMI Filters to Target Group Policies in Active Directory
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top