#StackBounty: #powershell #amazon-ec2 #windows-server #windows-server-2019 Given a virtual disk, get the pool it belongs to

Bounty: 100

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 the 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?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.