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?
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
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
Thanks again Luc