EDIT: I should add that the if block is only executed for some of the machines this is run against. So the D2fs property is only added to some of the records, not all.
$output = @()
do {
$obj = new psobject
$obj | add-member noteproperty Name $ENV:HostName
$obj | add-member noteproperty D1fs $disk1.freespace
if (%thereAreTwoDisks%) {$obj | add-member noteproperty D2fs $disk2.freespace}
$output += $obj
} until {%noMoreComputersInList%}
$output | exportTo-CSV c:\temp\log.csv -notype
The problem is that the second disk info never gets added to the output collection. Debuging tells me the $obj object DOES have the additional properties. They get dropped when the object is added to the collection. Is there a way to prevent this?