Skip to content

Setting ExecutionPolicy LocalMachine Undefined results in corrupted json settings file #2346

Closed

Description

@vors

Steps to reproduce

This is the second part of issue with #2342

There is a legitimate PS code that results in the corrupted JSON file

PS C:\Users\sevoroby> Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Undefined -Force
PS C:\Users\sevoroby> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process    RemoteSigned
  CurrentUser    RemoteSigned
Get-ExecutionPolicy : Error reading JToken from JsonReader. Path '', line 0, position 0.
At line:1 char:1
+ Get-ExecutionPolicy -List
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ExecutionPolicy], JsonReaderException
    + FullyQualifiedErrorId : Newtonsoft.Json.JsonReaderException,Microsoft.PowerShell.Commands.GetExecutionPolicyComm
   and

Expected behavior

No error.

Actual behavior

Error from NewtonSoft.JSON
It also prevents PS from starting, due to #2342

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
CLRVersion
GitCommitId                    v6.0.0-alpha.10
PSRemotingProtocolVersion      2.3
PSEdition                      Core
SerializationVersion           1.1.0.1
BuildVersion                   3.0.0.0
WSManStackVersion              3.0
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

Activity

  1. added
    Area-SideBySiderelated to ability to run PS7 side-by-side with WinPS or different versions of PS7
    WG-Enginecore PowerShell engine, interpreter, and runtime
    on Sep 22, 2016
  2. daxian-dbw commented on Sep 22, 2016

    @daxian-dbw
    Member
  3. mirichmo commented on Sep 27, 2016

    @mirichmo
    Member

    The simplest repro is to empty the config file:

    Set-Content <path to config file> -Value "{}"

    and then restart PowerShell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area-SideBySiderelated to ability to run PS7 side-by-side with WinPS or different versions of PS7Issue-BugIssue has been identified as a bug in the product

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions