2

I'm creating a random output from a CSV using Powershell and, while I have got it to work properly, the output is really annoying because of the excess spaces between each output.

$L = ipcsv ln.csv | Get-Random | Select-Object Letter | Format-Table -HideTableHeaders
$N = ipcsv ln.csv | Get-Random | Select-Object Number | Format-Table -HideTableHeaders

Write-Output $L
Write-Output $N

I just have a basic CSV up to test with. Letter and Number columns, going from A-J and 1-10, is in the CSV. It outputs a random letter and number as intended, but the output comes out like this:

F                                                                                                                                                                                     



9                                                                                                                                                                                     

All of those empty lines flood the console if I do any more than 5 outputs, which gets pretty annoying. Given that the outputs are not separated in the actual script, I want the output to look something like this:

F
9

Is there any way to achieve this output?

SirKasm
  • 21
  • 1
  • 2
    The formatting cmdlets add the space (this is by design - they are formatting output - hence the name!). If you want `Select-Object` to return a single object property (instead of a new object), use its `-ExpandProperty` parameter. – Bill_Stewart Aug 28 '16 at 01:46
  • Thank you, this does exactly as I wanted. – SirKasm Aug 28 '16 at 02:03
  • 1
    @Matt The duplicate given is questionable. – oɔɯǝɹ Aug 28 '16 at 08:49
  • 1
    The OP is misusing format table. I have seen it enough that I tried to make a catch most for it. The answer to that question covers what the OP wants in this one exactly. – Matt Aug 28 '16 at 17:02

0 Answers0