I am making a simple PowerShell script to launch using the Task Scheduler. The script should create a file, launch a .exe-Program and redirect all the output to the newly created file.
This is what my script looks like now:
# script.ps1
$LogFile = "C:\a\very\long\path\to\logfile.log"
C:
cd 'C:\path\to\exe\directory\' > $LogFile
.\program.exe > $LogFile
The program outputs symbols of the German alphabet: Ää Öö Üü ß. When I launch the program without file writing, it output the symbol the way it should: ä, ü. However, when I redirect the output to the log file, ä turns into õ and ü turns into ³.
I tried appending chcp 65001 and $PSDefaultParameterValues = @{ '*:Encoding' = 'utf8' }, but it didn't have any effect.
Funnily enough, this problem happens only in PowerShell. A similar script in Batch doesn't have this problem. Is there a way to fix it in PowerShell?
P. S. My PowerShell version is 5.1
-Encoding. Read the help to learn how to use it please.