A syntax error is a defect caused by source code that violates PowerShell’s grammatical rules. Common causes include mistyping a command, using the wrong function-call form, or forgetting a closing curly bracket. PowerShell often marks these problems with red squiggly underlines. section 23.1 section 23.2
Reduce syntax errors with practical checks:
- Watch for editor warnings, and check command and bracket spelling carefully. section 23.2
- Call functions with named parameters, such as My-Function -Param 1 -OtherParam 2, rather than method-style parentheses. section 23.2
- Enable Set-StrictMode -Version 2.0 to catch nonexistent properties and unassigned or mistyped variables. section 23.2
A typo that hides
Writing $CompuerName instead of $ComputerName can produce undesired results without an obvious PowerShell error. Strict mode turns references to unassigned variables into errors, making the typo easier to find. section 23.1 section 23.2
