I have a script that is run as a scheduled task which fails with an unexpected token error on on the line where $As is defined. If I remove the code, the script runs properl
PowerShell can detect following encodings from script file BOM: UTF-8, UTF-16 (LE and BE) and UTF-32 (LE and BE). If BOM is not present, then PowerShell use Encoding.Default for script file. So that, your UTF-8 script file should include BOM for UTF-8 to be recognized.
In your case, error happens due to PowerShell interpret all following characters: '‘’‚‛
— as single quote character. So, when your script file was read with incorrect encoding, some parts of what was string literals obtain special meaning and cause syntax violation.
$As = '[?ÀÃÂÃÄÅÆà áâãäåæ]','a'
^
$Ns = '[?Ññ]','n'
^
$Os = '[?ÒÓÔÕÖØðòóôõöø]','o'
^