Hello,
I’m having trouble when trying to output data from a hashtable. Below is my approach:
$CimSession=New-CimSession -ComputerName 'localhost'
foreach ($Session in $CimSession) {
$DiskModel = Get-CimInstance -ClassName Win32_DiskDrive
$DeviceID = Get-CimInstance -ClassName Win32_LogicalDisk
}
ForEach-Object `
-Begin { `
$HashOut = @{ } ; $Result = @() } `
-Process { `
$HashOut.DiskModel = $DiskModel.Model ; $HashOut.DeviceID = $DeviceID.DeviceID }`
-End { `
$Result += [pscustomobject]$HashOut }
My object ($Result) output is shown in brackets as a “nested” hash table.
DiskModel DeviceID
--------- --------
{SAMSUNG MZVLB512HAJQ-000H7, {C:, D:, E:, F:…}
WDC WD1002FAEX-00Z3A0, LITEON CV1-8B256-HP, WDC WD3202ABYS-01B7A0…}
My attempt to enumerate:
foreach ($h in $Result.GetEnumerator()) {
$($h.DiskModel), $($h.DeviceID)
}
but output still is not what I was aiming:
SAMSUNG MZVLB512HAJQ-000H7 WDC WD1002FAEX-00Z3A0 LITEON CV1-8B256-HP WDC WD3202ABYS-01B7A0 MTFDDAK256MBF-1AN1ZABHA WDC WD2003FZEX-00Z4SA0 C: D: E: F: G: J:
I would like under diskmodel property all the disk models to be listed and under DeviceID each DeviceID per disk.