I am attempting to convert the format of a file to UTF-8 with PowerShell using a technique outlined in another SO question.
I am using the following statement:
[IO.File]::WriteAllLines((Get-Item -Path ".\" -Verbose).FullName,"Test.txt")
The first parameter is the file path (C:\users\rsax\documents\Test), and the second parameter is the name of the file.
However, the command is not working, and is returning the following error:
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 <<<< ((Get-Item -Path ".\" -Verbose).FullName,"Test.txt")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
- I am running the command from PowerShell as an administrator.
- I have verified that the file is in the folder.
I can run other cmdlets in the directory that access the file, such as:
Get-Content Test.txt | Out-File TestOut.txt
I was not able to find an answer on the MSDN MethodInvocationException page.
What am I doing wrong?