Using the correct character encoding format

How to correctly encode PowerShell script files

Encoding errors occur, when the encoding of your script file does not match the expected encoding of PowerShell. Often encoding errors present themselves as parse errors in scripts.

PowerShell's default encoding varies depending on version.

  • In PowerShell 6, 7 or higher, the default encoding is UTF-8 without BOM on all platforms
  • In PowerShell 5.1 and below, the default encoding is usually Windows-1252.

It's not possible to force PowerShell to use a specific input encoding. For interoperability reasons, it's best to save scripts in a Unicode format with a BOM.


More information can be found here: File encoding in PowerShell

This page has been automatically translated and may contain grammatical errors or inaccuracies