Is it possible to output an array of Hash Tables that have different keys?
My experiment code is as follows:
$object1 = New-Object psobject -Property @{key1 = "Yep";
key3 = "Sure!"}
$object2 = New-Object psobject -Property @{key2 = "Yep";
key3 = "Sure!"}
$object3 = New-Object psobject -Property @{key1 = "Yep";
key2 = "Yep";
key3 = "Yep"}
Write-Host "Object 1 First"
$OutArray = @()
$OutArray += $object1
$OutArray += $object2
$OutArray
Write-Host "Object 2 First"
$OutArray = @()
$OutArray += $object2
$OutArray += $object1
$OutArray
Write-Host "Object 3 First"
$OutArray = @()
$OutArray += $object3
$OutArray += $object2
$OutArray += $object1
$OutArray
It seems as though they are stored in memory, for when you "Write-Host $OutArray" on either Object 1 or 2 first, you can see the keys and values.
Ultimately, I'm trying to export to CSV a list of ADUser accounts but the ADUser objects in question don't always have all the properties. It seems as though the first element of the array will set what the 'headers' are and then preclude the displaying of other keys, the first element might not have.
Any ideas?