I know this is an old thread but it was the first I found when searching. The += solution did not work for me. The code that I did get to work is as below.
#this bit creates the CSV if it does not already exist
$headers = "Name", "Primary Type"
$psObject = New-Object psobject
foreach($header in $headers)
{
Add-Member -InputObject $psobject -MemberType noteproperty -Name $header -Value ""
}
$psObject | Export-Csv $csvfile -NoTypeInformation
#this bit appends a new row to the CSV file
$bName = "My Name"
$bPrimaryType = "My Primary Type"
$hash = @{
"Name" = $bName
"Primary Type" = $bPrimaryType
}
$newRow = New-Object PsObject -Property $hash
Export-Csv $csvfile -inputobject $newrow -append -Force
I was able to use this as a function to loop through a series of arrays and enter the contents into the CSV file.
It works in powershell 3 and above.