0

I am trying to get disk number of particular volume. This volume is mapped into filepath instead of drive letter.

I am able to get uniqueid of volume from Get-volume cmdlet

$Volumepath = 'C:\MappedVolume2\disk2'
$uniqId = (get-volume -FilePath $Volumepath).UniqueId
Get-Disk -UniqueId $uniqId

This doesn't display any output or error.

This volume exists and UniqId displaying something like below

\?\Volume{0874487c-28c3-4c65-a374-b022fa07b20a}\

But unable to get any details. I need to get the disk number of volume.

Update:

I execute below commands

 > get-disk  | select UniqueId
   2036BB19DB62D3166C9DB900D48FC2BE
 > Get-Volume | select UniqueId
   \\?\Volume{0874487c-28c3-4c65-a374-b022fa07b20a}\

though they are named as uniqueid ,they are totally different. So they will not be compatible. Is there any other way to get disk number of volume ?

2
  • I've struggled with this for ages, and while the GUI shows everything in one cohesive place, I haven't found any way to do it via PowerShell. The problem is that the get-disk unique ID is a SCSI canonical name, while the get-volume one seems to be a Windows GUID of some sort. It's really frustrating and makes life very hard when you have a VM with lots of disks and need to reliably expand a specific one!
    – GregL
    Jan 17, 2018 at 13:01
  • This should be helpful: uvm.edu/~gcd/2013/01/which-disk-is-that-volume-on Jan 17, 2018 at 14:23

2 Answers 2

2

I know this is old, but in case anybody else is looking for the answer, this should solve for many "volume to disk" scenarios. For your scenario (and many others), you can use Get-Partition which can return the disk number. Give it the drive letter where the volume mount point resides. Using the $Volumepath variable in your example:

(Get-Partition -DriveLetter (Get-Item $Volumepath).PSDrive.Name).DiskNumber
0
Get-Partition | Select Guid, DriveLetter, DiskNumber, PartitionNumber, AccessPaths | 
Where {$_.Guid -Match '{0874487c-28c3-4c65-a374-b022fa07b20a}'}

or

Get-Partition | Select Guid, DriveLetter, DiskNumber, PartitionNumber, AccessPaths | 
Where {$_.AccessPaths -Match '\\?\\Volume{0874487c-28c3-4c65-a374-b022fa07b20a}'}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .