Skip to content

Prefs files get corrupted if used from both PowerShell and Windows PowerShell #148

@clairernovotny

Description

@clairernovotny

Expected Behavior

The prefs.xml file should not be corrupt.

Current Behavior

See https://stackoverflow.com/a/40098904/738188 for details. The issue is that the default encoding for Export-Clixml is different on Windows PowerShell and PowerShell Core. In the former it's UTF16LE/BE and in PowerShell Core it's UTF8 w/o a BOM.

The default encodings are documented if you look at the PS-version specific doc page:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-clixml?view=powershell-7.4#-encoding shows utf8NoBOM as the default while https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-clixml?view=powershell-5.1#-encoding shows Unicode as the default.

With many programs using PS and PS Core at the same time (in process consoles in VS Code, etc), it's highly likely that they'll step on each other.

Possible Solution

The solution should be to specify the -Encoding parameter on all uses of Export-Clixml and other commands that write files. That will prevent conflicting defaults.

Steps to Reproduce (for bugs)

prefs.xml.zip

Context

Frequent errors when launching a new terminal session from not being able to parse the prefs.

Your Environment

  • Module version used:
  • Operating System and PowerShell version:
    PS Core 7.4.6 and Windows PowerShell on Windows 11.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions