Q: What is my VHD file's drive letter?

Use PowerShell to check a VHD's drive letter.

John Savill

November 16, 2012

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A: If you mounted a virtual hard disk (VHD) and want to check its drive letter, use the following two Windows PowerShell commands:

$DiskNumber = (Get-VHD “d:temptemp2gb.vhdx”).DiskNumber
$DriveLetter = (gwmi Win32_DiskPartition -filter "DeviceID like 'Disk #$DiskNumber,%'").PSBase.GetRelated('Win32_LogicalDisk') | Select-object -ExpandProperty DeviceID

Another option using PowerShell, is to enter this:

$disks = Get-CimInstance -ClassName Win32_DiskDrive | where Caption -eq "Microsoft Virtual Disk" 
foreach ($disk in $disks){ 
   $vols = Get-CimAssociatedInstance -CimInstance $disk -ResultClassName Win32_DiskPartition 
   foreach ($vol in $vols){ 
       Get-CimAssociatedInstance -CimInstance $vol -ResultClassName Win32_LogicalDisk | 
          where VolumeName -ne 'System Reserved' 
   } 
}

Here's an example of output I received:

DeviceID DriveType ProviderName VolumeName Size FreeSpace -------- --------- ------------ ---------- ---- --------- N: 3 TempVHD 2111827968 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like