# PS 5.1, Get-ComputerInfo generates blank lines at the top

**URL:** <https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296>\
**Category:** PowerShell Help\
**Created:** [January 11, 2025, 4:44am UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296 "2025-01-11T04:44:26Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![Query-01](https://avatars.discourse-cdn.com/v4/letter/q/c89c15/32.png) [@Query-01](https://forums.powershell.org/u/Query-01)\
**Post date:** [January 15, 2025, 3:58pm UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/21 "2025-01-15T15:58:26Z")

</div>

> [@LearnLaughOps](#):
>
> To answer your question bluntly - the extra blank line is the tableheader.

@LearnLaughOps – Please do review the initial image I posted, What ‘Table’ are you referring to?

> [@LearnLaughOps](#):
>
> ```auto
> $_info.PSObject.Properties | ForEach-Object {
> "$($_.Name) : $($_.Value)"
> }
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![LearnLaughOps](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/learnlaughops/32/5688_2.png) [@LearnLaughOps](https://forums.powershell.org/u/LearnLaughOps)\
**Post date:** [January 15, 2025, 5:24pm UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/22 "2025-01-15T17:24:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Query-01](https://avatars.discourse-cdn.com/v4/letter/q/c89c15/32.png) [@Query-01](https://forums.powershell.org/u/Query-01)\
**Post date:** [January 16, 2025, 3:41am UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/23 "2025-01-16T03:41:27Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Query-01](https://avatars.discourse-cdn.com/v4/letter/q/c89c15/32.png) [@Query-01](https://forums.powershell.org/u/Query-01)\
**Post date:** [January 17, 2025, 11:18am UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/24 "2025-01-17T11:18:11Z")

</div>

> [@krzydoug](#):
>
> This is the output of your code.
> 
> ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/6/64a25a1eeee9038a8253971825b20cef8a7eeb70.png)
> 
> By default, powershell formats 4 or less properties as a table. 5 or more is displayed as a list
> 
> ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/8/8419408ddc73e90de8410222d90a5101531ef7bd.png)
> 
> So please, share the code that is causing the issue you show in your screenshot so we can assist you.

@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:

```auto
_info = Get-computerInfo "OsName", "OSDisplayVersion", "OsVersion", "osinstalldate"
write-output $_info

```

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.

```auto
Invoke-Command -ComputerName Pc1, Pc2, Pc3 -Scriptblock { 

_info = Get-computerInfo "OsName", "OSDisplayVersion", "OsVersion", "osinstalldate"
write-output $_info

 }

```

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?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 17, 2025, 11:49am UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/25 "2025-01-17T11:49:37Z")

</div>

> [@Query-01](#):
>
> Is there a solid way to confirm the cause or, just keep playing with it until the dust settle’s?

If you want to have the output a certain way do not count on the default behavior of PowerShell. Instead format the output the way you like. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![Query-01](https://avatars.discourse-cdn.com/v4/letter/q/c89c15/32.png) [@Query-01](https://forums.powershell.org/u/Query-01)\
**Post date:** [January 17, 2025, 1:28pm UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/26 "2025-01-17T13:28:31Z")

</div>

> [@Olaf](#):
>
> > [@Query-01](#):
> >
> > Is there a solid way to confirm the cause or, just keep playing with it until the dust settle’s?
> 
> … do not count on the default behavior of PowerShell.

@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.

---

<div class="post-metadata">

**Author:** ![psdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/psdarwin/32/2063_2.png) [@psdarwin](https://forums.powershell.org/u/psdarwin)\
**Post date:** [January 17, 2025, 2:18pm UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/27 "2025-01-17T14:18:12Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![LearnLaughOps](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/learnlaughops/32/5688_2.png) [@LearnLaughOps](https://forums.powershell.org/u/LearnLaughOps)\
**Post date:** [January 17, 2025, 6:51pm UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/28 "2025-01-17T18:51:38Z")

</div>

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…

[PowerShell | Out-Default](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/out-default?view=powershell-5.1)

---

<div class="post-metadata">

**Author:** ![Query-01](https://avatars.discourse-cdn.com/v4/letter/q/c89c15/32.png) [@Query-01](https://forums.powershell.org/u/Query-01)\
**Post date:** [January 18, 2025, 7:33am UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/29 "2025-01-18T07:33:42Z")

</div>

> [@psdarwin](#):
>
> @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.

@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”.

> [@psdarwin](#):
>
> It’s not like bash where output is designed primarily for screen display. PowerShell wants to give you objects.

Right there generates a huge Thank You, along with what @LearnLaughOps → [posted](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/28), “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](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/6), {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`.

> [@psdarwin](#):
>
> 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.

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.

> [@psdarwin](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Query-01](https://avatars.discourse-cdn.com/v4/letter/q/c89c15/32.png) [@Query-01](https://forums.powershell.org/u/Query-01)\
**Post date:** [January 18, 2025, 7:39am UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/30 "2025-01-18T07:39:18Z")

</div>

> [@krzydoug](#):
>
> Have you tried just not using Write-Output? You don’t need it there at all.

@krzydoug – I missed this until now, Yes I tried not using `Write-Output`; disastrous results.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [February 17, 2025, 7:39am UTC](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296/31 "2025-02-17T07:39:27Z")

</div>

Closed on February 17, 2025, 7:39am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

[Previous page](https://forums.powershell.org/t/ps-5-1-get-computerinfo-generates-blank-lines-at-the-top/25296.md?page=1)
