In PS 5.1 I wrote this little func to ensure that the result of Processor will always be an array but for some strange reason it does not work. Do you know why?
function ConvertTo-Array($result) {
[bool]$isArray = ($result.getType() | Select-Object basetype).toString() -eq "System.Array"
if ($isArray -eq $false) {
return @($result)
}
return $result
}
$table = @{
"Processor" = ConvertTo-Array(Get-wmiobject Win32_Processor | Select-Object -Property Name, Number*);
}
$machinedata = @{
"Machine Info" = $table;
}
write-output (ConvertTo-Json $machinedata -Depth 3)
If I do this instead it works
...
"Processor" = @(Get-wmiobject Win32_Processor | Select-Object -Property Name, Number*);
...