PowerShell: How to Mount a Virtual Hard Disk (VHD)

Posted December 5, 2008 by Rob Rogers in Windows

If you wish to access the contents of a VHD file without having to run Virtual PC or Virtual Server, you can do so by using PowerShell and running a couple of commands from the command line.

1. Open PowerShell.

2. Input and execute the following command:

$objVHDService = get-wmiobject -class "Msvm_ImageManagementService" -namespace "root\virtualization" -computername "."

To Mount a VHD file:

Input and execute the following command:

$objVHDService.Mount("e:\virtual\test\test.vhd")

Where e:\virtual\test\test.vhd is the path to the desired virtual hard disk.

To Unmount a VHD file:

Input and execute the following command:

$objVHDService.Unmount("e:\virtual\test\test.vhd")

Where e:\virtual\test\test.vhd is the path to the desired virtual hard disk.

 

About Rob Rogers

Once a prolific author here on Tech-Recipes, Rob has moved on to greener pastures.
View more articles by Rob Rogers

The Conversation

Follow the reactions below and share your own thoughts.

  • Yong Shik Lee

    very good!

  • Where is the hard disk actually mounted? I just tried this on my Server 2008 Workstation and can not find the VHD anywyere – it does not show up in My Computer nor in disk management (within Server Manager)

  • mahesh

    How to get the drive letter for mounted drive.

  • mahesh

    How to get the drive letter for mounted drive ?
    I am able to see mounted drive on file browser but i want to use this drive letter in script. How can i get this drive letter using powershell command.