<p>I have a file saved as UCS-2 Little Endian I want to change the encoding so I ran the following code:</p>

<pre><code>cat tmp.log -encoding UTF8 &gt; new.log
</code></pre>

<p>The resulting file is still in UCS-2 Little Endian.  Is this because the pipeline is always in that format? Is there an easy way to pipe this to a new file as UTF8?</p>

[{'answer_id': 76734, 'author': 'driis', 'author_id': 13627, 'author_profile': 'https://Stackoverflow.com/users/13627', 'pm_score': 5, 'selected': False, 'text': '<p>I would do it like this:</p>\n\n<pre><code>get-content tmp.log -encoding Unicode | set-content new.log -encoding UTF8\n</code></pre>\n\n<p>My understanding is that the -encoding option selects the encdoing that the file should be read or written in.</p>\n'}, {'answer_id': 76808, 'author': 'Lars Truijens', 'author_id': 1242, 'author_profile': 'https://Stackoverflow.com/users/1242', 'pm_score': 7, 'selected': True, 'text': '<p>As suggested <a href="https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets#64937">here</a>:</p>\n\n<pre><code>Get-Content tmp.log | Out-File -Encoding UTF8 new.log\n</code></pre>\n'}, {'answer_id': 24057859, 'author': 'user572730', 'author_id': 572730, 'author_profile': 'https://Stackoverflow.com/users/572730', 'pm_score': 3, 'selected': False, 'text': '<p>load content from xml file with encoding.</p>\n\n<p>(Get-Content -Encoding UTF8 $fileName)</p>\n'}, {'answer_id': 31521946, 'author': 'sba923', 'author_id': 1808955, 'author_profile': 'https://Stackoverflow.com/users/1808955', 'pm_score': 1, 'selected': False, 'text': "<p>If you are reading an XML file, here's an even better way that adapts to the encoding of your XML file:</p>\n\n<pre><code>$xml = New-Object -Typename XML\n$xml.load('foo.xml')\n</code></pre>\n"}, {'answer_id': 67678498, 'author': 'Geordie', 'author_id': 796634, 'author_profile': 'https://Stackoverflow.com/users/796634', 'pm_score': 0, 'selected': False, 'text': '<p>PowerShell\'s get-content/set-content encoding flag doesn\'t handle all encoding types.  You may need to use IO.File, for example to load a file using Windows-1252:</p>\n<pre><code>$myString = [IO.File]::ReadAllText($filePath, [Text.Encoding]::GetEncoding(1252))\n</code></pre>\n<p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding?view=net-5.0" rel="nofollow noreferrer">Text.Encoding::GetEncoding</a>\n<a href="https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencodings?view=net-5.0" rel="nofollow noreferrer">Text.Encoding::GetEncodings</a></p>\n'}]
['https://Stackoverflow.com/questions/76482', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2582/']