Skip to content

Make newly created PowerShell files default to UTF-8 *with BOM* to avoid encoding misinterpretation #1771

@mklement0

Description

@mklement0

Summary of the new feature

  • VSCode creates UTF-8 files without BOM by default.
  • This causes Windows PowerShell (but not PowerShell Core) to misinterpret any non-ASCII-range characters, because, in the absence of a BOM, it defaults to the system's legacy "ANSI" code page (e.g., Windows-1252).

It seems that this has been a perennial pain point (whose root cause isn't obvious), as evidenced by, for instance, by #629 or this StackOverflow question.

Making the extension default all new PowerShell files to UTF-8 with BOM solves that problem.

Such files would be both cross-edition and cross-platform compatible (given that PowerShell Core still correctly interprets the BOM, even though it doesn't require it).

Proposed technical implementation details

I don't know how it works in the context of extension-specific settings, but in the general settings.json file you can simply add the following:

"[powershell]": {
  "files.encoding": "utf8bom"
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions