How to Automatically Mount a VHDX Virtual Drive on Startup in Windows 11

Virtual Hard Disks (VHDX files) are incredibly useful in Windows 11 for creating secure, encrypted containers, isolating development environments, or managing backups. While creating and mounting a VHDX file manually through Disk Management is straightforward, Windows unmounts these virtual drives every time you restart your computer.

If you rely on a VHDX file for daily tasks, manually remounting it after every reboot quickly becomes tedious. Fortunately, you can automate this process using a simple PowerShell script combined with the Windows Task Scheduler.

Step 1: Create the PowerShell Mounting Script

First, we need to write a one-line script that tells Windows where your VHDX file is located and instructs it to mount the drive.

  1. Open the Start menu, search for Notepad, and open it.
  2. Paste the following command into the blank document. Replace the file path with the actual location of your VHDX file:
    Mount-DiskImage -ImagePath "C:\Path\To\Your\VirtualDrive.vhdx"
  3. Click File > Save As.
  4. Change the “Save as type” dropdown to All Files (*.*).
  5. Name the file MountVHDX.ps1 and save it in a safe location (such as your Documents folder).

Step 2: Automate the Script with Task Scheduler

Because mounting a disk requires administrator privileges, you cannot simply place this script in your Windows Startup folder. Instead, we must use Task Scheduler to run it with elevated permissions.

  1. Open the Start menu, search for Task Scheduler, and open the application.
  2. In the right-hand “Actions” pane, click on Create Task…. (Do not click “Create Basic Task”).
  3. In the General tab:
    • Name the task something recognizable, like “Automount VHDX”.
    • Check the box at the bottom that says Run with highest privileges. This is critical; the script will fail without it.
  4. Switch to the Triggers tab and click New….
    • Change the “Begin the task” dropdown to At log on.
    • Ensure the “Enabled” box is checked, then click OK.
  5. Switch to the Actions tab and click New….
    • Ensure the Action is set to “Start a program”.
    • In the Program/script box, type exactly: powershell.exe
    • In the Add arguments box, type the following, replacing the path with the location of the script you created in Step 1:
      -ExecutionPolicy Bypass -WindowStyle Hidden -File "C:\Path\To\Your\MountVHDX.ps1"
    • Click OK.
  6. Switch to the Conditions tab.
    • Uncheck the box that says Start the task only if the computer is on AC power (especially if you are using a laptop).
  7. Click OK to save and create the task.

Testing the Automation

To verify the setup works, simply restart your computer. Upon logging in, Windows will invisibly execute the PowerShell script in the background, and your virtual drive will automatically appear in File Explorer, ready for use.

Get the best tech tips delivered straight to your inbox.

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