There are several approaches, but it is quite simple:
$content = Get-Content file.txt
$content | Foreach {$_.TrimEnd()} | Set-Content file.txt
You may need to configure the parameter Encodingin the Set-Content cmdlet to get the file in the desired encoding (Unicode, ASCII, UTF8, etc.).
source
share