Correlate Physical Device ID to Volume Device ID

Viewed 5364

I'm trying to utilize WMI via PowerShell to run through SAN storage on remote servers to grab the Windows disk management volume label.

The only way I've found to do this is to correlate the volume device id (\\?\Volume{34243...} with the physical disk device ID (\\.\PHYSICALDRIVE01).

However, I haven't been able to find out how to link those two fields together. Is this possible with WMI?

2 Answers

I have done a script that collects the most important stuff from volume and disk WMI. its used with getting information from a Remote Desktop server where a lot of disks are mounted but can be hard to find who is using which disk. its using AD to query the user and connect it with the SID to find the file path. so its a matter of first collecting all the data from the different disk commands and then combine the outputs. the most important command to bind disk data with volume data is the get-partition that shows deviceid

Function Get-VHDMount {

[cmdletbinding()]

Param(
  [Parameter(Position=0,ValueFromPipeline=$True)]
  [ValidateNotNullorEmpty()] 
  [OBJECT[]]$Computername,
  [STRING]$RDSPATH = '\\rdsprofiles'
)
    foreach ($computer in $Computername) {

        $RDSItems      = (Get-ChildItem $RDSPATH -Recurse -Filter *.vhdx)
        $VolumeInfo    = invoke-command -ComputerName $computer -scriptblock  {Get-Volume | select *}
        $VHDMountInfo  = Get-WmiObject Win32_Volume -ComputerName $computer |where Label -eq 'user Disk' 
        $partitioninfo = invoke-command -ComputerName $computer -scriptblock  {Get-Partition | Select-Object DiskNumber, @{n='VolumeID';e={$_.AccessPaths | Where-Object { $_ -like '\\?\volume*' }}}}

        foreach ($VHDmount in $VHDMountInfo) {
            $adinfo = Get-ADUser ($VHDmount.name | Split-Path -Leaf)

            [PSCUSTOMOBJECT]@{
                Computername = $computer
                username     = $VHDmount.name | Split-Path -Leaf
                displayname  = $adinfo.name
                SID          = $adinfo.SID
                deviceid     = $VHDmount.deviceid
                capacity     = ([MATH]::ROUND(($VHDmount.capacity) / 1gb))
                HealthStatus = ($VolumeInfo | where ObjectId -eq ($VHDmount.deviceid)).HealthStatus
                DiskNumber   = ($partitioninfo | where Volumeid -eq ($VHDmount.deviceid)).DiskNumber
                Path         = ($RDSItems | where fullname -like "*$($adinfo.SID)*").FullName
            }
        }
    }
}
Related