0

I'm making a list of infomation that i what to display. But anytime i run the line that is needed to show the info, it's gonna place 2 blank lines over the output.

Code looks like this

$Pro = Get-WmiObject -Class win32_processor

$pro | select-Object Name,NumberofCores,NumberOfLogicalProcessors | format-list

Is there something else i can do to make it remove the 2 lines from the output? (Can't show the blank lines because they don't show)

Name : Intel(R)
NumberOfCores : x
NumberOfLogicalProcessors : x
  • the `Format-List` cmdlet is what is creating the two trailing blank lines. the simplest way to remove those 2 lines is to assign the output to a $Var & then use`$Var[0..2]`. ///// generally speaking, one should NOT use the `Format-*` cmdlets for anything other than _final_ output to a plain text file OR to the screen. so, if you intend to use the info later in your script, you likely otta avoid using those cmdlets. – Lee_Dailey Jan 09 '20 at 12:45
  • 1
    Possible duplicate of [this1](https://stackoverflow.com/questions/47453079/remove-blank-lines-from-output) and [this2](https://stackoverflow.com/questions/32252707/remove-blank-lines-in-powershell-output). Most `Format-*` cmdlets have this quirk. – leeharvey1 Jan 09 '20 at 12:48
  • @leeharvey1 The first link that you provide "this1" had just what i needed to change it, thanks :) $pro | Select-Object Name | Format-list| Out-string | ForEach-Object { $_.Trim() } –  Jan 09 '20 at 12:54
  • @Toppers - you are most welcome! glad to help a little ... [*grin*] – Lee_Dailey Jan 09 '20 at 12:55
  • Does this answer your question? [Remove blank lines from output?](https://stackoverflow.com/questions/47453079/remove-blank-lines-from-output) – Dharman Mar 20 '20 at 11:48

2 Answers2

1

The Answer from @leeharvey1 is what was needed.

$pro | Select-Object Name | Format-list| Out-string | ForEach-Object { $_.Trim() 
Dharman
  • 30,962
  • 25
  • 85
  • 135
0

This is the only solution i've could figure to overcome the blank lines issue:

$Pro = Get-WmiObject -Class win32_processor

$pro | select-Object Name,NumberofCores,NumberOfLogicalProcessors | format-list | Out-String | % ($_) {$_.Trim()}
JimShapedCoding
  • 849
  • 1
  • 6
  • 17