The first part of your issue is that you have two objects, not one, but the way you’re creating your final object means you’re squashing them into a single object. This is what causes the lines to be merged; if you go about it differently, this won’t happen.
The second part is a trickier question. The easy answer is with a calculated property from Select-Object, which modifies the data to display what you want. I’ll come back to the trickier answer in a moment.
As you can see, you have a few options! But the core of the matter is that you have a collection of objects, so you either need to continue along the pipeline to enumerate them, or opt to enumerate them yourself with `foreach` or `ForEach-Object` when building your result objects. Multiple lines in a table = multiple output objects.
The trickier answer I mentioned before is that you can keep your raw data in bytes if you wish and delegate the display to PS’s formatting subsystem. Doing so is more complicated than I can really cover in a short forum post. Kevin Marquette covers it partially in one of his deep dive posts on PSCustomObject.
Thank you for the ideas, Joel! I’ll give Kevin’s presentation a good read.
Generally, I have a Franken-script, hacked from Internet ideas, that uses Select-Object and the formatting math. Personal challenge is to make it more elegant.
I learned a lot from your code of building with a hash-table. Many thanks for your explanation. From your example, I can see the flow through the pipeline.
What I didn’t catch before was using “foreach-object”. I’ve not previously used this cmdlet, so I had to overcome a reading bias that it was the classic foreach. Nope, two different things.
I played with a few permutations of trying to get a pre-made PSObject fed into the script block using -ArgumentList, perhaps the way Invoke-Command can be fed a variable that exists locally