encoding problem

I’m trying to run a script that analyzes some log files, and the logs are in Dansih. I can run the script inline (as in entering the lines one by one to the terminal) without a problem, but when I try to run the script as a file (.\script.ps1 ARGS), the encoding breaks and dose not process the danish charachters. I have tried many thing Including

 $OutputEncoding = [System.Text.Encoding]::UTF8 
$PSDefaultParameterValues = @{ '*:Encoding' = 'utf8' } 

and have appended

 -Encoding UTF8 
every where I can, but still no result, and the strange part is if I run the script line by line there is no problem.
for example

$targets = ‘Kørselsdato’, ‘Tidspunkt’, ‘JobId’, ‘Antal læste på tabellen AFSENDNEMSMS’, ‘Køretid i minutter’
$targets | Out-File “.res.txt”

this will work line by line but not when I run it as a script file

result of runing as a script :


Kørselsdato
Tidspunkt
JobId
Antal læste på tabellen AFSENDNEMSMS
Køretid i minutter

result of runing line by line :


Kørselsdato
Tidspunkt
JobId
Antal læste på tabellen AFSENDNEMSMS
Køretid i minutter

Didn’t have a problem with this as a .ps1

$targets = 'Kørselsdato', 'Tidspunkt', 'JobId', 'Antal læste på tabellen AFSENDNEMSMS', 'Køretid i minutter'
$targets | Out-File C:\tmp\test.txt

If you open your text file in notepad and do a SaveAs, what does it say next to the save button what the encoding is?

UTF8 Signature and I also used this

 Out-File -Encoding utf8 “res.txt” 

If you skip the out-file and just output the $targets variable to the console when you run it as a script.
Does it output the content correctly or is it scrambled there as well?

no, The same problem

What is the output if you type/run:

$OutputEncoding
[console]::OutputEncoding

Before you run the script?