title: Write to a file encoded in USC-2 LE BOM, batch script
body: <p>I want to be able to create an *.rdp file from a bat file, however I just noticed that rdp files are actually encoded as <code>USC-2 LE BOM</code>, while my bat is producing a <code>UTF-8</code> file, here's what I do:</p>
  
  <pre><code>@echo off
  &gt; file.rdp (
  echo screen mode id:i:2
  ... bunch of echoes
  echo lastparam:: )
  </code></pre>
  
  <p>This produces what I expected but is encoded in <code>UTF-8</code>, is there a way to either:</p>
  
  <ul>
  <li>Create a file, set its encoding and then apend to it?</li>
  <li>Produce the output from <code>&gt;</code> encoded in <code>USC-2 LE BOM</code> directly to a file?</li>
  <li>Encode the <code>UTF-8</code> file into <code>USC-2 LE BOM</code> within the same bat file?</li>
  </ul>
  
  <p>I want to write this and other files using a bat so I can set Read-only permissions to the generated file and cannot think of any other alternative. This way, I'll be able to deploy a bunch of preconfigured read-only rdp files.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Thanks to <a href="https://stackoverflow.com/a/56068054/7369171">LotPigs answer</a> and <a href="https://stackoverflow.com/a/54069584/7369171">this underrated answer</a> I was able to use powershell to change the encoding, wanted to share how I was able to include the powershell encoding within the batch</p>
  
  <pre><code>@echo off
  &gt; utf8file ( ... )
  ECHO Get-Content utf8file ^&gt; utf16.rdp &gt; powerShellScript.ps1
  powershell.exe -ExecutionPolicy Bypass -File powerShellScript.ps1
  </code></pre>