1
votes

I have the below code to retrieve a Japanese or localized string from an mht file. i have used almost all the encoding params listed here(unknown,string,unicode,bigendianunicode,utf8,utf7,utf32,ascii,default,oem) and verified. it always prints the junk characters instead of original Chinese or Japanese name

$log = "c:\scripts\meta.mht"
$patt = 'title'
$indx = Select-String $patt $log | ForEach-Object {$_.LineNumber}
write-host (Get-Content $log)[$indx] | out-file -encoding string c:\scripts\temp1.xml

can some one help me how to print the localized string? which encoding param should i use? i have tried with all the listed params but no luck (unknown,string,unicode,bigendianunicode,utf8,utf7,utf32,ascii,default,oem)

thanks in advance.

1

1 Answers

4
votes

Try changing your encoding for Get-Content like this:

write-host (Get-Content -Path $log -Encoding UTF8)[$indx] | out-file -encoding UTF8 c:\scripts\temp1.xml

I'm not sure if you'll need UTF8 or UNICODE, try both for Get-Content and Out-File.