AutomatedOutlookSignature
AutomatedOutlookSignature copied to clipboard
special characters are not displayed correctly in out-file
The script doesn't genereate the correctly encoded specials characters like german umlauts. I already tried to set the encoding for out-file to utf8, but that does only work for values from active directory. If I output some static values directly within the script (because they are not all defined in active directory), they are not displayed as they should.
I could use ü and so on, but this only works for the html-signature, not for the text-version.
Hello.
Do you mind giving me some examples so I can take a look into this for you and see if we can get a resolution.
Thank you.
Hi @captainqwerty , thanks for your quick answer.
I enclosed a sample script, generated files and screenshots, which can be used for testing. To test all is working well you need to have a AD-User with special characters, e.g. äöü or ß in the used attributes.
Kind regards.
Wonderful, thank you for your effort to help this project.
I have planned in looking at this on the weekend :) Hopefully find a resolution for yourself and further improve this little project.
Have you checked which encoding you used for the script itself? Try saving the script encoded as UTF-8 with BOM, and then run it again.
I can confirm changing ASCII econding to UTF8 when generating output files works correctly for accented chars "ěščřžýáíé" used in Czech lang.
IMO UTF8 is relatively safe option today and should work on all major scenarios.
I am very sorry for the big delay in looking at this - I have been swamped recently. I will do some testing with @nocturneop15's suggestion and if that works I shall make a new release detailing it.
I can suggest using optional "sanitize" function that can also address german "umlauts" and others. I use this one: ` function get-sanitizedUTF8Input{ Param( [String]$inputString ) $replaceTable = @{"ß"="ss";"a"="a";"á"="a";"â"="a";"a"="a";"ä"="a";"a"="a";"a"="ae";"ç"="c";"e"="e";"é"="e";"e"="e";"ë"="e";"i"="i";"í"="i";"î"="i";"i"="i";"?"="d";"n"="n";"o"="o";"ó"="o";"ô"="o";"o"="o";"ö"="o";"o"="o";"u"="u";"ú"="u";"u"="u";"ü"="u";"ý"="y";"?"="p";"y"="y";"ř"="r"}
foreach($key in $replaceTable.Keys){
$inputString = $inputString -Replace($key,$replaceTable.$key)
}
#$inputString = $inputString -replace '[^a-zA-Z0-9]', '' # seats out spaces and non-alphanumeric
return $inputString
} `
Another approach would be to use System.IO.File.WriteAllText instead of Out-File
System.IO.File.WriteAllText covers most of the special characters including german "umlauts" and others
Original:
$style + $signature | Out-File -FilePath "$file.htm" -Encoding ascii
Edited:
$htmlcontent = $style + $signature
$filepath = "$file.htm"
[System.IO.File]::WriteAllText($filepath, $htmlcontent)
Changing the encoding to unicode worked for me. Windows saves .txt files in Outlook with default UTF-16LE encoding.
In version 5 I have added -encoding as a parameter for selecting an encoding. I hope this resolve the issue.
@NikPPPPPP - I will also take a look at using System.io.file as well in the next version. Once I have confirmation this is fixed I shall close the issue.
With the new -Encoding Parameter option this should now be resolved. I have done some testing with Unicode and UTF-8 and it appears to be fine now.