Change encoding of Powershell created file to UTF8 instead of UCS-2 LE
<p>I'm using powershell to create a file, I need this file to be UTF8 Encoded, thus far all of the attempts I've tried have failed.</p>

<p>Inspecting the file in Notepad++ shows UCS-2 LE BOM as the encoding.  Is it possible for powershell to use UTF8 instead?</p>

<p>So far I've tried -encoding utf8 and currently I'm using <code>[IO.File]::WriteAllLines($filename, $text)</code>   </p>

<p>There may be an underlying issue (forgive me, very new to Powershell) that is causing the problem as I receive this error in the console however the file is being created:</p>

<pre><code>    Cannot process argument because the value of argument "path" is null. Change the value of argument "path" to a non-null value.
    + CategoryInfo          : InvalidArgument: (:) [Out-File], PSArgumentNullException
    + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.OutFileCommand
    + PSComputerName        : 50.19.209.240

ChangeFileModeByMask error (3): The system cannot find the path specified.
    + CategoryInfo          : NotSpecified: (ChangeFileModeB...path specified.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : 50.19.209.240
</code></pre>

<p>Edit:</p>

<p>Edited after answer given to provide more info.</p>

<p>Details from the file:</p>

<pre><code>write-host "Creating Application.conf in UTF-8"
$filename = "c:\application.conf"
[IO.File]::WriteAllLines($filename, $text, [System.Text.Encoding]::UTF8) 
</code></pre>

<p>the output in the console is still erroring as per the above.   </p>