#PSTip Finding the drive letter of a mounted disk image

Note: This tip requires PowerShell 3.0 or above.

Windows 8 and Windows Server 2012 included cmdlets to manage storage. One such cmdlet is Mount-DiskImage which can be used to mount ISO, VHD, and VHDX files. But, unfortunately, this cmdlet does not give us information on the drive letter assigned to the newly mounted disk image. Knowing the drive letter might be a very important thing when using these cmdlets in a script.

So, how do we find the drive letter? Here is one method:

$before = (Get-Volume).DriveLetter
Mount-DiskImage -ImagePath C:\test\Test.vhd -StorageType VHD
$after = (Get-Volume).DriveLetter
compare $before $after -Passthru

There are other methods too–such as using PowerShell eventing or background jobs, etc. Let us save that for future tips! 🙂

Share on: