Windows – How to get disk number from volume map point

disk-volumehard drivepowershellwindows

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 ?

Best Answer

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
Related Topic