List Volume GUIDs by Disk

Windows Server 2016 Backup says it wants to back up a volume that has no letter. What volume is it? What disk(s) is that volume on?

Windows Server 2016 Backup selection 1

Mountvol lists GUIDs of mounted volumes and their drive letters, but that doesn’t help identify the disk it’s on if the volume doesn’t have a letter.

This PowerShell command, adapted from this thread, lists GUIDs and space but still doesn’t tell me which disk the volumes are on:

Get-WMIObject win32_volume | Format-List -property Label,DriveLetter,DeviceID,SystemVolume,Capacity,Freespace

This command, adapted from this answer, gives the drive number as well:

Get-WMIObject Win32_LogicalDisk | Foreach-Object {
Get-WmiObject -Query "Associators of {Win32_LogicalDisk.DeviceID='$($_.DeviceID)'} WHERE ResultRole=Antecedent"
}

However note that it omits volumes without drive letters due to the parent/child association on “DeviceID”.

This post has the following code:

$diskdrive = gwmi win32_diskdrive
foreach($drive in $diskdrive)
{
	"`nDrive: DeviceID: $($drive.deviceid.substring(4)) - Model: $($drive.model)"
	$partitions = gwmi -Query "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=`"$($drive.DeviceID.replace('\','\\'))`"} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
	foreach($part in $partitions)
	{
		"`tPartition: $($part.name)"
		$vols = gwmi -Query "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=`"$($part.DeviceID)`"} WHERE AssocClass = Win32_LogicalDiskToPartition"
		foreach($vol in $vols)
		{
			"`t`t$($vol.name)"
		}
	}
}

This one does show the partitions that don’t have drive letters, but no details are listed, again because “volumes” (actually logical disks) are retreived by the associated DeviceID.

Another post builds on that but it looks like that would also not list volume GUIDs.

In the end, I went with a modified version of the first command, showing Capacity and FreeSpace in MB. That allowed me to find the partition by “eyeballing” it in diskmgmt.msc.

Get-WMIObject win32_volume | Format-List -property Label,DriveLetter,DeviceID,SystemVolume,
@{Name="Capacity MB";Expression={[math]::truncate($_.Capacity / 1MB)}},
@{Name="Freespace MB";Expression={[math]::truncate($_.Freespace / 1MB)}}

I saw that Windows Server 2016 Backup was showing the 450MB Recovery partition as not having a drive letter. But it also lists a Recovery partition with a name. Inspecting the contents, they are not the same:

Windows Server 2016 Backup selection 2

No doubt this is because, after an in-place upgrade of Server 2012 R2 to 2016, I now have two recovery partitions, one 300MB and one 450MB. This article explains how get back to only one partition, but for now I’ll just back them both up

4 thoughts on “List Volume GUIDs by Disk

  1. Geoff Duke

    The Storage module was added to PowerShell in Windows 8/2012, and contains the commands Get-Disk, Get-Partition, and Get-Volume, which might also be useful. [https://technet.microsoft.com/en-us/itpro/powershell/windows/storage/storage]

  2. Mark Berry Post author

    Thanks Geoff. Those commands do look like they would be easier to work with than the WMI commands. However, I’m still not seeing a link between disks and volumes. Are you? I was hoping that Get-Volume would have a property returning an array of DiskNumbers, which would map back to values in Get-Partition and Get-Disk. Similarly, Get-Disk and Get-Partition could have arrays of partitions and volumes, respectively.

  3. God

    That’s because, strictly speaking, there is no link between volumes and drives. This is because you have situations where there is no 1:1 mapping. Take a RAID or Storage Spaces – this is a situation where a volume is “linked” to multiple drives. On the other hand, take a RAM disk – this is a situation where a volume is not “linked” to any drive at all.

    Then there’s the grey area around VHD[X]s and iSCSI targets, where the VDS or the iSCSI initiator invents an entire storage stack (including a virtual SCSI controller!) for the “drive” – but it’s backed by another volume (in the case of a VHD[X] – beautifully turtles-all-the-way-down!), or a remote device that could well be another software abstraction (if the target is also a VHD, for example) – and entirely separate APIs need to be used to identify them.

    The fundamental issue is that a drive is a physical object, and a volume is a software abstraction. While the simple cases of “one drive=one volume” and “one partition=one volume” can be guessed at by correlating output from WMI classes such as Win32_LogicalDiskToPartition and Win32_DiskDriveToDiskPartition, more complex arrangements “break the spell”, and fall afoul of the issues above.

  4. Mark Berry Post author

    @god, I see your point, that what the OS calls a “drive” may in fact be an abstraction itself, e.g. a RAID array, iSCSI, SAN, etc. But my (perhaps simplified) understanding is that all of that runs below the OS level. The OS, where I am running Windows Server Backup, just expects drives and volumes. If I run diskmgmt.msc, every volume is on a “disk”; I was just trying to confirm which disk held a particular volume. Hmm… come to think of it, it is possible to set up RAID within the OS. I’ve never done that, so I don’t know how that would appear in diskmgmt.msc. I suspect it would show multiple physical disks joined as a logical disk, similar to the way RAID appears in hardware managers, then allow adding volumes to the logical disk.

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.