Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PSv3 - Collection of objects dropping additional object properties

$
0
0

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?





Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>