We have PowerShell objects that contain PSCustomObjects in the form of an array. To export this information to a text or Excel file we need to be able to flatten the data.
Example code:
$Fruits = [PSCustomObject]@{
Name = 'Banana'
Colors = [PSCustomObject]@{
Name = 'Green'
},
[PSCustomObject]@{
Name = 'Yellow'
}
Taste = [PSCustomObject]@{
Name = 'Good'
},
[PSCustomObject]@{
Name = 'Bad'
},
[PSCustomObject]@{
Name = 'Awful'
}
}
Generates:
$Fruits | fl *
Name : Banana
Colors : {@{Name=Green}, @{Name=Yellow}}
Taste : {@{Name=Good}, @{Name=Bad}, @{Name=Awful}}
To be able to have a clean export, the desired result should be something like this:
Name | Color | Taste
---- | ----- | -----
Banana | Yellow | Good
Banana | Green | Bad
Banana | | Awful
How is it possible to unravel this object?