Convert Array of object to CSV...with a twist
i have array of objects (cert: provider returns such array) need convert csv file (or xml or whatever).
normally convert creating custom ps object , adding each entry since have each of attributes in object, create new psobject using that. no big deal. however, have added new properties each array object, , name of property dynamic cannot add few attributes list.
example:
array[0]:
property1
property2
property3
customproperty1
customproperty2
array[1]:
property1
property2
property3
customproperty1
customproperty3
how can create new custom ps object of properties listed can export this?
note: fine having each entry in object have properties, if blank. guessing whatever solution works may require that.
hi johnson,
you can first retrieving property-names , selecting this:
[string[]]$properties = @() $array | %{ $_.psobject.properties | select-object -expandproperty name | %{ $properties += $_ } } $properties = $properties | select-object -unique $array | select-object $properties | export-csv "blablablub.csv" cheers,
fred
there's no place 127.0.0.1
Windows Server > Windows PowerShell
Comments
Post a Comment