@LearnLaughOps – Please do review the initial image I posted, What ‘Table’ are you referring to?
I am aware of the capability of the ForEach-Object to remove “TableHeader’s”, I’m just not sure you are speaking of the same output image I initially provided; please clarify.
I’m referring to the object returned by Get-ComputerInfo. I’m providing a method to remove the blank line issue you encountered when formatting the output.
@LearnLaughOps The only concern I had with the output of Get-ComputerInfo, were the blank-lines shown in the initial image I posted. That image display’s a ‘list’ formatted output; not a table. The code which generated that output has since been revised, ultimately resolving that ‘blank-line’ issue, as-well-as having been deleted.
@krzydoug Even though I got rid of those blank-lines by rewriting the script, I felt the need to keep picking at this to confirm --what is actually causing the issue. That said, your above post mentions PowerShell’s default formatting; four line’s or less = table, five or more line’s = list. Compared to the original snippet I provided, please consider the following:
The above will display a table; four lines of less. The code below generates a list, using the same four properties; not five or more. Notice when placing the original code within the -Sciptblock { ... }, the blank-lines return.
To be clear, I’m not trying to fix this, but rather identify what is triggering this concern, so I can recognize then dodge it in the future. I originally thought it was Get-ComputerInfo or Write-Output. Now it seems Invoke-Command has its finger’s in the mix. Is there a solid way to confirm the cause or, just keep playing with it until the dust settle’s?
@Olaf – Well that’s not fun, this feel’s like one of those undocumented gotcha’s that people workaround. I’ll assume that is why everyone was guiding me to csv, xml or http; lesson learned.
@Query-01 I think it’s not an undocumented gotcha, but it’s how PowerShell works. Remember that PowerShell output is by default object output, not console output. It’s not like bash where output is designed primarily for screen display. PowerShell wants to give you objects. If you want those objects to look a certain way on the screen or in a file, you get to determine that yourself. If you want to do that with bash or a command line exe, you will have to do contortions to do it. PowerShell makes output formatting easy and configurable by default.
It does give you a console output format that works, but if you want it pretty, then you get to make it pretty. If you want quick and dirty output, then you get that by default.
A little digging this morning brought me to a cmdlet that PowerShell automatically adds to the end of every pipeline Out-Default. I think if you are interested in how the formatting works you should reference the below link.
Out-Default decides how to format and output the object stream. If the object stream is a stream of strings, Out-Default pipes these directly to Out-Host which calls the appropriate APIs provided by the host. If the object stream does not contain strings, Out-Default inspects the object to determine what to do. First it looks at the object type and determines whether there is a registered view for this object type…
@psdarwin – Thank you for both the correction (gotcha’s) --and pointing out that “PowerShell output is by default object output, not console output.”. I never knew or, read about the details of PowerShells’ default output, as it relates to formatting. I was working off of, or otherwise expecting some type of uniform output, soley based on what I’ve seen other scripts generate to the screen.
Once again I hadn’t researched enough of any particular script, to either recognize any implied, included formatting code or, as stated above, learned about “PowerShells’ default output”.
Right there generates a huge Thank You, along with what @LearnLaughOps → posted, “a cmdlet that PowerShell automatically adds to the end of every pipeline Out-Default.” I did previously skim over the Out-default and Format-Custom article’s, it seemed like a lot of work, --given everything I’ve seen output to the console so-far, has had uniform\neat output. For whatever reason the wording: “object output” and the cmdlet out-default, until now, had me expecting --output from code/scripts will have either Format-Table or Format-List, text-generated output, with the option of using Format-Custom.
A previous post from Olaf, {slapped}/informed me, “If you insist you could convert the output to a string an remove all empty lines from it before you output it.” ← that triggered further research. Before Olafs’ post, I always thought the screen was receiving ‘text’; output from the pipeline.
Thanks to the feedback in this thread, I now understand differently; and will also return and read out-default.
This (contortionism) is the current experience of which I was not expecting. I found myself seemingly writing extended one-liner’s, that only came close to the desired visual screen\host output; prompting this thread.
The “quick and dirty” isn’t a bad thing, its just the empty lines and in some case’s, the spacing. It is, what it is, this will provided for a better contortionist training environment.