1

My system: Windows 11 64 bit with all updates to date.

I have a VHD on my hard drive. If i go into Disk Management i can click Action > Attach > Select File and i see a mapped drive.

I now turn to a cmd prompt and run the following:

diskpart 

{Press enter} and type

select vdisk file="C:\Virtual Drives\MyVhd.vhdx"

this too does the same thing but using a cmd prompt.

I am attempting to attach this drive at startup (so will eventually create a Scheduled Task) but if i execute the command in one row

diskpart select vdisk file="C:\Virtual Drives\MyVhd.vhdx"

under the directory c:\Windows\System32 or c:\Windows\System from a cmd prompt it doesnt map/attach the drive.

I looked at https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/diskpart but it doesnt clarify how i can move the command line to DiskPart or how i can run it from the command line?

1
  • To create a diskpart script, create a text file that contains the Diskpart commands that you want to run, with one command per line, and no empty lines. You can start a line with rem to make the line a comment. To use: diskpart /s scriptname.txt learn.microsoft.com/en-us/windows-server/administration/… Commented Jun 10, 2023 at 17:34

1 Answer 1

1

It's easier by using the PowerShell command Mount-VHD.

Example command :

Mount-VHD -Path c:\test\testvhdx.vhdx

If you intend running this command from a .bat file, use this:

powershell "Mount-VHD -Path c:\test\testvhdx.vhdx"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .