VMware Cloud Community
halibut
Enthusiast
Enthusiast
Jump to solution

Retrieving information from an embedded hash table

I know this should be simpler but I just don't know the syntax to retrieve specific keys and subkey entries.  My hope is to display the information within the hash tables to a table or any other format needed.

here is the current snippet.

$Disk = @{}

ForEach ($vSCSIController in ($vmView.Config.Hardware.Device | Where {$_.DeviceInfo.Label -match "SCSI Controller"})){

    #'Unit Number: ' + $vSCSIController | %{$_.UnitNumber}

    ForEach ($vDiskDevice  in ($vmView.Config.Hardware.Device | Where {$_.ControllerKey -eq $vSCSIController.Key}))

        {

        $Label = $vDiskDevice.DeviceInfo | %{$_.Label}

        [string]$BusNum = $vSCSIController | %{$_.BusNumber}

        [string]$DiskDev = $vDiskDevice | %{$_.UnitNumber}

        [string]$SCSIid = $BusNum + ":" + $DiskDev

        $HD = Get-VM $VM | get-harddisk | where {$_.Name -eq $Label}

        $ID = @{   

            "Label" = $Label

            "CapGB" = [System.Math]::Round($HD.CapacityKB / 1MB, 2)

            "Filename" = $HD.Filename

            "StorageFormat" = $HD.StorageFormat

            "ScsiID" = $SCSIID

            }

        $Disk.Add([string]($HD.Name),$ID)

        }

    }

#

#"Disk Name" + "`t" + "SCSI Bus" + "`t" + "Capacity in GB" + "`t" + "Filename" + "`t" + "StorageFormat"

#'==============================================================================================================='

$Disk.keys

The $Disk.Keys is where I am needing the help.  How would I display all values if Label is "Hard Disk 10"? and in the order listed near the end of the snippet?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$hd = $disk.GetEnumerator() | where {$_.Value.Label -eq "Hard disk 10"} | Select -ExpandProperty Value 

Via $hd you can now access the properties.

$hd.Label / $hd.CapGB / ...


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$hd = $disk.GetEnumerator() | where {$_.Value.Label -eq "Hard disk 10"} | Select -ExpandProperty Value 

Via $hd you can now access the properties.

$hd.Label / $hd.CapGB / ...


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
halibut
Enthusiast
Enthusiast
Jump to solution

Thanks again Luc

0 Kudos