Often there are cases when exporting to CSV, there are nested arrays.
I want to clone the object, so I can expand the list into a flat table
$Employees = @(
[pscustomobject]@{ UserId = 0 ; Name = 'Bob'; Events = @( 'a'..'e' ) }
[pscustomobject]@{ UserId = 1 ; Name = 'Jen'; Events = @( 'b', 'c', 'q', 'z' ) }
)
$Employees | ConvertTo-Csv
"UserId","Name","Events"
"0","Bob","System.Object[]"
"1","Jen","System.Object[]"
$Employee's can be any type
Do I clone? Do I add-member but emit the object multiple times? It doesn't have to work in all cases. If it does for a chunk it'd be worth it.
$ExpectedOutput = @(
[pscustomobject]@{ UserId = 0 ; Name = 'Bob'; EventId = 'a' }
[pscustomobject]@{ UserId = 0 ; Name = 'Bob'; EventId = 'b' }
[pscustomobject]@{ UserId = 0 ; Name = 'Bob'; EventId = 'c' }
[pscustomobject]@{ UserId = 0 ; Name = 'Bob'; EventId = 'd' }
[pscustomobject]@{ UserId = 0 ; Name = 'Bob'; EventId = 'e' }
[pscustomobject]@{ UserId = 1 ; Name = 'Jen'; EventId = 'b' }
[pscustomobject]@{ UserId = 1 ; Name = 'Jen'; EventId = 'c' }
[pscustomobject]@{ UserId = 1 ; Name = 'Jen'; EventId = 'q' }
[pscustomobject]@{ UserId = 1 ; Name = 'Jen'; EventId = 'z' }
# csv
"UserId","Name","EventId"
"0","Bob","a"
"0","Bob","b"
"0","Bob","c"
"0","Bob","d"
"0","Bob","e"
"1","Jen","b"
"1","Jen","c"
"1","Jen","q"
"1","Jen","z"