Formatting Data into a .CSV file

Dell has a pretty useful tool called Dell Command Monitor that gets verbose information about their hardware as well as the health state of different pieces of hardware. I read some of their DCM documentation and a healthstate of 5 = “healthy”. If it is over 20 then you have some type of potential failure.

(Get-CimInstance -Namespace root/DCIM/SYSMAN -ClassName DCIM_FAN).HealthState  

When that command is run on my laptop within PowerShell ISE it returns the following.

5
5

I have two fans in my Precision laptop so that makes sense. I wanted to export this and some other information into a .CSV file within a larger PowerShell script.

I create an array and then I collect some information like PC name, OS version, BIOS version etc… and I want to also get the health state of some things like the FAN and MEMORY. It all works perfect when I pipe it to OUT-GRIDVIEW or if I pipe it to OUT-FILE.

but when I try to export to a .CVS file instead of seeing 5,5 for my FAN healthstate I see this: System.Object[]

I’ve tried:

$results | Export-Csv "c:\temp\info.csv" -Append
$results | Export-Csv "c:\temp\info.csv" -Append -Encoding Default
$results | Export-Csv "c:\temp\info.csv" -Append -Encoding ASCII
$results | Export-Csv "c:\temp\info.csv" -Append -Encoding Unicode
$results | Export-Csv "c:\temp\info.csv" -Append -Encoding BigEndianUnicode
$results | Export-Csv "c:\temp\info.csv" -Append -Encoding OEM
$results | Export-Csv "c:\temp\info.csv" -Append -Encoding UTF7
$results | Export-Csv "c:\temp\info.csv" -Append -Encoding UTF8

Not sure what else to try since that is all of the -encoding options.
Thank you.

… indicates an array. If you want to output that to a single cell in a CSV file you should concatenate it upfront. … maybe like this:

(Get-CimInstance -Namespace root/DCIM/SYSMAN -ClassName DCIM_FAN).HealthState -join ', '

That worked!! Thank you.