A
A
Artem Kiryanov2018-11-15 14:49:39
PowerShell
Artem Kiryanov, 2018-11-15 14:49:39

How to remove line breaks in PowerShell?

There is a small script

Get-WmiObject win32_computersystem name | select name -ExpandProperty Name | Out-File C:\Distrib\test.txt 
$a=Get-Content C:\Distrib\test.txt
$b=$a.split('-')
$c=$b[$b.Length-1]
$c = $c | foreach {"S"+$_} 
$c | Out-File C:\Distrib\test.txt

When opening with Notepad++, I see CRLF.
5bed5d226ebe4087556177.png
It is necessary for me that when saving there was no line break.
I've googled all over and can't find the best solution.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kiryanov, 2018-11-15
@hacker342

'S'+(Get-WmiObject win32_computersystem).Name.Split('-')[-1] |
Out-File C:\Distrib\conf.txt -NoNewline -Enc default

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question