Phantom PowerShell Syntax Errors

Objective

To identify and resolve common syntax errors in PowerShell Worklets caused by hidden Unicode or "smart" characters resulting from copy-pasting code.

Problem / Symptoms

A PowerShell Worklet fails during execution, displaying syntax errors in the Automox Activity Log, despite running successfully when executed manually inside PowerShell ISE or a local console session.

Common error messages include:

  • The string is missing the terminator: '.

  • Missing closing '}' in statement block or type definition

  • Unexpected token '...' in expression or statement

  • You must provide a value expression following the '-like' operator.

Root Cause

These syntax failures occur because the PowerShell interpreter cannot parse certain non-standard Unicode characters.

When code is copied and pasted from web pages, rich-text editors (like Microsoft Word or TextEdit), or messaging platforms (like Slack or Teams), standard ASCII characters are often automatically converted into "smart" or stylized Unicode equivalents:

Standard ASCII CharacterStylized Unicode EquivalentIssue in PowerShell
Straight Single Quote (')Left/Right Curly Quotes ( )Breaks string termination
Straight Double Quote (")Left/Right Curly Quotes ( )Breaks string termination
Hyphen / Minus (-)En Dash / Em Dash ( )Breaks cmdlet parameters/operators

While graphical editors like PowerShell ISE may automatically handle or ignore these formatting differences, the headless PowerShell engine invoked by the Automox Agent strictly requires standard ASCII encoding.

Resolution Steps

To resolve the syntax errors, convert the stylized characters back to standard ASCII equivalents using these steps:

1. Inspect Parameter Highlighting

Look at the script inside a plain-text code editor (such as VS Code or Notepad++):

  • Check parameter flags (e.g., -ExecutionPolicy or -Name). If the dash and parameter name do not highlight as a cmdlet argument, the dash is likely an En Dash () or Em Dash (). Delete and retype the hyphen (-).

2. Replace Smart Quotes

Scan all quoted strings in your code:

  • Ensure quotes are plain straight quotes (' or ") rather than slanted/curly quotes ( or ).

3. Re-Save with UTF-8 Encoding

  1. Copy the script text into a plain-text editor (e.g., VS Code or Notepad++).

  2. Set the file encoding explicitly to UTF-8 (without BOM).

  3. Copy the cleaned text from the editor and paste it directly back into the Automox Worklet code window.

Was this article helpful?
0 out of 0 found this helpful