Mounting VHD files by command line

Today I needed to copy a DVD ISO image file outside a HyperV VM disk.

I tried by using Remote desktop copy and paste feature but it failed.
Looking over the web, I discovered that it is possible to mount .vhd file in order to access to the contained files directly from the hosting machine.  This solution worked fine for me.

According to this post, you have to:

  • open an Administrative Command Prompt and type:
    diskpart
  • then type:
    select vdisk file=<VHD file>
    for example:
    select vdisk file=”C:\temp\mydisk.vhd”
  • then type:
    attach vdisk

When you don’t need it anymore, start diskpart command again (if needed) and:

  • then type:
    select vdisk file=<VHD file>
  • then type:
    detach vdisk
  • then type:
    exit