-1

When I run this command, it returns the output with lots of blank lines.

Get-Host | Select Name, Version | Format-List

I tried using ExpandProperty but it still leaves me with one blank line at the end of the output, is there a way to remove the last blank line?

Get-Host | Select -ExpandProperty Name, Version | Format-List 
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
BlackFox7
  • 11
  • 1
  • 1
  • 4
  • Why you need to remove them? Do you want to log the output into file or just to show it on the console? – autosvet Nov 23 '17 at 10:28
  • What do you call blank line? Empty line in the console or a property that has no value? – Manu Nov 23 '17 at 10:35
  • I'm using this output in another script – BlackFox7 Nov 23 '17 at 10:37
  • Please be more specific, your problem is unclear you should provide an image or code of the ouput as it appears in your console to show others what's the real problem. – Manu Nov 23 '17 at 10:58
  • Don't use `Format-List` then, if you use the output somewhere else. Use `ConvertTo-Csv` or something similar. – Thomas Glaser Nov 23 '17 at 11:01

1 Answers1

3

If you really need the format that Format-List provides, then you can use Out-String and Trim() to get rid of empty lines:

Get-Host | Select Name,Version | Format-List | Out-String | ForEach-Object { $_.Trim() }

But, depending on your needs, it's probably easier to just use CSV or the JSON format for further processing (see ConvertTo-Json or ConvertTo-Csv).

Thomas Glaser
  • 1,670
  • 1
  • 18
  • 26