Why does PowerShell flatten arrays automatically?
Use the unary form of ,
, PowerShell's array-construction operator:
"a:b;c:d;e:f".Split(";") | ForEach-Object { , $_.Split(":") }
That way, the array returned by $_.Split(":")
is effectively output as-is, as an array, instead of having its elements output one by one, which happens by default in a PowerShell pipeline.
,
creates a - transient - wrapper array whose only element is the array you want to output. PowerShell then unwraps the wrapper array on output, passing the wrapped array through.