PowerShell function to list disk volumes backed by SSD RRS feed

  • General discussion

  • So one day, I needed to list volumes on a system and I wanted to identify volumes backed by solid state drives. I trolled  various forums and blogs and I found mostly kludgy solutions or solutions based on bad assumption and it became clear I'll have to do the heavy lifting myself. Query of Win32_Volume associations seemed like the best way forward but that opened a couple of problems. CIM & WMI Win32 classes didn't seem to accurately or consistently describe the solid states and I've never worked with associations before so there's that too. 

    Fortunately, Windows 2012 R2 added storage class object functionality and MSFT_Volume and MSFT_PhyiscalDisk suddenly looked like my best friends for this solution. There are so many other gems in this namespace it was hard not to get distracted by so much 'shiny'. Anyway, these class objects looked great but issue #2 slapped in the face. Then I found get-CimAssociatedInstance and with a little trolling and experimentation, I put this function together. I just needed basic information but it easy to add more properties to the output as needed.  

    function List-Drives {    
        $NameSpace = 'Root\Microsoft\Windows\Storage'
        $VolInfo=Get-CimInstance -query "SELECT * FROM MSFT_Volume" -Namespace $NameSpace | Where-Object{($_.driveletter -ne $null) -and ($_.driveletter -ne 0)}
        $VolInfo |%{
                'Drive' = $_.driveletter
                'Label' = $_.FileSystemLabel
                'Size' = "{0:N1}" -f $($_.Size/1GB)
                'Remaining' = "{0:N1}" -f $($_.SizeRemaining/1GB)
                'Type'=(Get-CimAssociatedInstance -InputObject $(Get-CimAssociatedInstance -InputObject $_ -Association MSFT_PartitionToVolume) -Association MSFT_DiskToPartition -PipelineVariable SerialNumber | Get-PhysicalDisk).MediaType    
        Return $disks
    List-Drives | ft -AutoSize

    Friday, September 6, 2019 11:49 PM