This command will produce 1 extra line at the top and 3 more at the bottom.
Get-Process | select Name | ft -HideTableHeaders | Out-File .\process.txt
The same thing happens with other lists such as reading a directory.
Same result as in previous answer, but in another syntax:
Get-Process | foreach{ $_.Name} > .\process.txt
There still is empty line in the end, though
You can turn it into a string and trim it:
(Get-Process | select Name | ft -HideTableHeaders | Out-String).Trim() | Out-File .\process.txt
Rather than three, there is now only one empty line at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With