Share via


Get-WmiObject class for diskpart list volume

Question

Tuesday, September 2, 2014 2:08 PM

Hi All,

I am looking for a class to list all hidden volumes. It can be accessed via "Info" field in DISKPART list volume. I've checked Win32_Volume but can't find anything, infact it doesn't work with hidden volumes.

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
               
  Volume 0     C                NTFS   Partition     68 GB  Healthy    System
  Volume 1         Third        NTFS   Partition     49 GB  Healthy    Hidden

Thank you,

Naz

All replies (16)

Saturday, September 6, 2014 2:01 PM ✅Answered | 2 votes

Maybe not the best way, but this works for me and gives a nice object with which to work:

[string]$temp = Invoke-Command -Computername $RMHost -ScriptBlock {$dpscript = @"
list volume
"@;$dpscript | diskpart}
$vols = $temp -split "\s(?=V)"
$labels = ($vols[2] -split "(\s+)(?=-)")[0] -split "\s+"
$Results = $vols[3..($vols.count-1)] | %{
   New-Object PSObject -property @{
      "$($labels[0])$($labels[1])" = $_.substring(0,10).trimend()
      $labels[2] = $_.substring(13,3).trim()
      $labels[3] = $_.substring(17,11).trim()
      $labels[4] = $_.substring(30,5).trim()
      $labels[5] = $_.substring(37,10).trim()
      $labels[6] = $_.substring(49,7).trim()
      $labels[7] = $_.substring(58,9).trim()
      $labels[8] = $_.substring(67,8).trim()
   }
}
$Results

I hope this post has helped!


Thursday, August 4, 2016 6:11 PM ✅Answered | 1 vote

I know this is old, but in case anyone is interested in the same topic, the Get-Partition powershell cmdlet is really just a wrapper to query the root\Microsoft\Windows\Storage WMI namespace for the MSFT_Partition class. So you can still query it with Powershell v2 as long as the classes exist prior to Server 2012/Windows 8.


Tuesday, September 2, 2014 3:51 PM

Win32_LogicalDisk should work for you, it accesses these properties, including volume name:

PSComputerName
Status
Availability
DeviceID
StatusInfo
__GENUS
__CLASS
__SUPERCLASS
__DYNASTY
__RELPATH
__PROPERTY_COUNT
__DERIVATION
__SERVER
__NAMESPACE
__PATH
Access
BlockSize
Caption
Compressed
ConfigManagerErrorCode
ConfigManagerUserConfig
CreationClassName
Description
DriveType
ErrorCleared
ErrorDescription
ErrorMethodology
FileSystem
FreeSpace
InstallDate
LastErrorCode
MaximumComponentLength
MediaType
Name
NumberOfBlocks
PNPDeviceID
PowerManagementCapabilities
PowerManagementSupported
ProviderName
Purpose
QuotasDisabled
QuotasIncomplete
QuotasRebuilding
Size
SupportsDiskQuotas
SupportsFileBasedCompression
SystemCreationClassName
SystemName
VolumeDirty
VolumeName
VolumeSerialNumber
Scope
Path
Options
ClassPath
Properties
SystemProperties
Qualifiers
Site
Container

I hope this post has helped!


Tuesday, September 2, 2014 3:52 PM

It will include mapped drives too, FYI.

I hope this post has helped!


Tuesday, September 2, 2014 6:54 PM

Unfortunately this class doesn't include volumes with hidden flag.

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
               
  Volume 0     C                NTFS   Partition     68 GB  Healthy    System
  Volume 1         Third        NTFS   Partition     49 GB  Healthy    Hidden
  Volume 2     D   Third_Log    NTFS   Partition   5117 MB  Healthy

PS C:\Windows\system32> gwmi -class Win32_LogicalDisk | Format-Table

DeviceID                      DriveType ProviderName                  FreeSpace                Size VolumeName
                                                       
C:                                    3                             18443284480         73371578368
D:                                    3                              5309485056          5365559296 Third_Log

Volume 1 is not getting picked up by Win32_LogicalDisk.


Tuesday, September 2, 2014 7:19 PM | 1 vote

What do you need that you can't get from Win32_Volume?  

I hope this post has helped!


Wednesday, September 3, 2014 1:28 PM

My apologies, I wasn't clear. I can't get hidden volumes (volume 1 in the example below) with Win32_LogicalDisk.


Wednesday, September 3, 2014 1:31 PM

Use Win32_Volume, it shows volumes with no drive letter.

I hope this post has helped!


Wednesday, September 3, 2014 6:55 PM

No, Win32_Volume doesn't list/detect hidden volumes. It was my initial guess as well but no luck. They have to be accessible via WMI somehow.


Wednesday, September 3, 2014 7:34 PM

Have you tried CIM_StorageVolume?


Wednesday, September 3, 2014 7:51 PM

That doesn't work either.  He's got a 'really' hidden volume, I just noted the missing drive letter and thought it was pseudo-hidden.  I've tried every relevant disk, drive, partition, and volume WMI class but none of them show the hidden volume....

I hope this post has helped!


Thursday, September 4, 2014 3:14 AM

Hi nsnidanko,

You may try to use command "get-partition | fl * " .

You can get disk number and parition number via filtering null value of " Accesspaths " .

Best Regards

Elton JI

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time.
Thanks for helping make community forums a great place.


Thursday, September 4, 2014 12:52 PM

Unfortunately get-partition in not available in Powershell version 2, thus solution will exclude 2008 R2 and older. Reason I went with wmi as it's universal across all OS versions. I was hopping to avoid parsing output of diskpart as it's different across OS versions as well.


Friday, September 5, 2014 8:51 PM

I've decided to go parse output of diskpart

[string]$temp = Invoke-Command -ComputerName $RMHost -ScriptBlock {$dpscript = @"list volume"@$dpscript | diskpart}

Invoke-Command returns Object and not a string. When I cast it as string I lose multiple line output and end up with this:

Which makes it impossible to parse. How do I get multi-line string from Invoke-Command so I can split lines after with "`t"?


Monday, September 8, 2014 1:26 PM

This is a very clever way! Thank you, I will be using your solution.

P.S.

Not marking it as an answer to keep topic open as maybe someone has idea if its possible to get this data via WMI.


Friday, August 4, 2017 4:08 PM

What about Volume ### ?