Search code examples
powershelldisk-partitioning

DISKPART vs PowerShell Get-Volume


In DISKPART.EXE, I get the info when multiple mount points are assigned to a volume. In the picture we see that Drive G: can also be accessed using D:\SQL\MSSQL13.MSSQLSERVER\DATA\ or D:\BlaBla:

DISKPART result

But I can't find the same info using PowerShell's Get-Volume or Get-WMIObject -Class Win32_Volume. Does anyone knows how to extract this info using a native PowerShell function?

Get-Volume result

I thought of extracting the info by calling DISKPART.EXE inside PowerShell but I would prefer an native PowerShell function like Get-Volume.


Solution

  • Perhaps surprisingly, you can look up mount points via the Win32_MountPoint class:

    Get-WmiObject Win32_MountPoint | Select-Object Directory, Volume
    

    Further details can be obtained by looking up the references:

    Get-WmiObject Win32_MountPoint | ForEach-Object {
        $dir = [wmi]$_.Directory | Select-Object -Expand Name
        $vol = [wmi]$_.Volume
        New-Object -Type PSObject -Property @{
            Directory   = $dir
            Label       = $vol.Label
            DriveLetter = $vol.DriveLetter
            FileSystem  = $vol.FileSystem
            DeviceId    = $vol.DeviceId
        }
    }