6

I'm trying to correlate volumes (as enumerated from win32_volume for those where DriveType = 3) back to win32_physicaldisk instances. Everything that I've seen in my research points to the answer being "it's not possible", but then again, I didn't read the entire Internet. :) I'm currently getting the information out of diskpart, but am running into limitations with that approach.

As a bonus, if the answer is "no, and here's the reason why", that would be useful, too.

3
  • If you're fortunate enough to be using Server 2012+ everywhere, you can use the Get-Partition and Get-Disk cmdlets for PowerShell 4. If not, well, yeah, back to your question... which I'd like top know the answer to as well. Dec 15, 2014 at 22:37
  • @HopelessN00b: I am that fortunate. At a quick glance, this might work. However, it doesn't seem to be listing volumes that don't currently have an access path (i.e. drive letter or mount point). That would be a show stopper for this particular application.
    – Ben Thul
    Dec 15, 2014 at 23:22
  • not sure if i'm completely off base, but what about using a different class, like Win32_LogicalDisk? It looks like it supports the same DriveType method, and links to physicaldisk better. Jan 13, 2015 at 0:41

3 Answers 3

0

This doesn't necessarily answer the wmi question but here's an alternative. Use a diskpart script and parse out the results.

Create a diskpart script like so:

select disk 3
list volume

Execute the diskpart script from powershell (or something to parse out the results):

$volumes = diskpart /s myDiskpartScript.txt
$volumes |? {$_ -match 'Volume (\d)'} |% {$matches[1]}

This will grab all the volumes associated with disk 3 and output the capture group from the regex match to show each volume number. You can add additional capture groups to grab information like the label, file system type, and more.

Unfortunately this isn't a remote method and may not suit your needs, but still may be useful to know.

0

You sohuld use:

Get-WmiObject -Class Win32_DiskPartition

and

Get-WmiObject -Class Win32_DiskPartition | Select-Object -Property *

Can also be used to query remote computers for this information.

0

This isn't specifically volumes->disks, but you could pipe the partitions in to Get-Disk. For example, this will tell you the disk associated with drive letter C:

Get-Partition -DriveLetter C | Get-Disk

(Tested on PS version 5.1)

You must log in to answer this question.

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