Given a virtual disk, get the pool it belongs to

I have this monstrosity:

Get-Volume | ForEach-Object {
    $VolObj = $_
    $ParObj = Get-Partition | Where-Object { $_.AccessPaths -contains $VolObj.Path }
    $DiskObj = Get-Disk | Where-Object { $_.Number -eq $ParObj.DiskNumber }
    $PsDriveObj = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -contains $VolObj.DriveLetter }

    Get-StoragePool -IsPrimordial $false | ForEach-Object {
        $pool = $_
        Get-PhysicalDisk -StoragePool $pool | ForEach-Object {
            $disk = $_
            if ($disk.UniqueId -eq $volume_id) {
                $pool_id = $pool.UniqueId 
            }
        }
    }

    ...

}

The problem with this piece of code is in the line if ($disk.uniqueid -eq $volume_id).

Instead of $volume_id I've tried .SerialNumber and UniqueId of the multiple objects (VolObj, ParObj, DiskObj and PsDriveObj) but these are either empty or return the wrong ID (the IDs of these objects are either vol*** since I run it on an EC2 instance or in the format of {...}), so the if is never true.

Is there a straightforward way of achieving this?


The following helped the poster with his problem:

Get-VirtualDisk -FriendlyName "VDisk01" | Get-StoragePool

References:

  • Get-StoragePool
  • Get-VirtualDisk