1

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?

4
  • Does someting like this work: Get-VirtualDisk -FriendlyName "VDisk01" | Get-StorageTier?
    – harrymc
    Jul 18 at 17:20
  • @harrymc Thanks but no, it returns nothing
    – DeepSpace
    Jul 18 at 17:30
  • 1
    What about: Get-VirtualDisk -FriendlyName "VDisk01" | Get-StoragePool?
    – harrymc
    Jul 21 at 13:00
  • @harrymc Good enough for me :) Thanks. If you want you can post as an answer and I'll accept
    – DeepSpace
    Jul 21 at 13:31
1
+100

The following helped the poster with his problem:

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

References:

2
  • For future reference: Is there anything in the Get-StoragePool docs that suggests it can be used in combination of Get-VirtualDisk in this way?
    – DeepSpace
    Jul 21 at 13:53
  • 1
    Get-StoragePool has many variants for the multiple ways it can be called. The 9th one (!) is Get-StoragePool ... [-VirtualDisk <CimInstance>] ..., which hints about this.
    – harrymc
    Jul 21 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.