Powershell – WriteAllLines method – ‘Access is Denied’
<p>I am attempting to convert the format of a file to UTF-8 with PowerShell using a   <a href="https://stackoverflow.com/questions/5596982/using-powershell-to-write-a-file-in-utf-8-without-the-bom/#answer-5596984">technique outlined in another SO question</a>. </p>

<p>I am using the following statement:</p>

<pre><code>[IO.File]::WriteAllLines((Get-Item -Path ".\" -Verbose).FullName,"Test.txt")
</code></pre>

<p>The first parameter is the file path (C:\users\rsax\documents\Test), and the second parameter is the name of the file.</p>

<p>However, the command is not working, and is returning the following error:</p>

<pre><code>Exception calling "WriteAllLines" with "2" argument(s): "Access to the path 'C:\users\rsax\documents\Test' is denied."
At line:1 char:25
+ [IO.File]::WriteAllLines &lt;&lt;&lt;&lt; ((Get-Item -Path ".\" -Verbose).FullName,"Test.txt")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
</code></pre>

<ul>
<li>I am running the command from PowerShell as an administrator.</li>
<li>I have verified that the file is in the folder.</li>
<li><p>I can run other cmdlets in the directory that access the file, such
as: </p>

<p>Get-Content Test.txt | Out-File TestOut.txt</p></li>
<li><p>I was not able to find an answer on the <a href="https://msdn.microsoft.com/en-us/library/system.management.automation.methodinvocationexception(v=vs.85).aspx" rel="nofollow noreferrer">MSDN
MethodInvocationException page</a>.</p></li>
</ul>

<p>What am I doing wrong?</p>