Skip to content

PWSH 7.5preview5: Breaking change in ConvertTo-Json??? Parameter '-EnumsAsStrings' must now be specified #24386

@UselessGuru

Description

@UselessGuru

Prerequisites

Steps to reproduce

Since 7.5preview5 enum values in objects are no longer returned as string by default.
Parameter '-EnumsAsStrings' must now be specified to get the same result as in previous releases.
7.5preview4 and 7.4.5 behave identitical and do not require '-EnumsAsStrings'.
I cannot see this change documented anywhere.

Note: I cannot find a way to produce 'copy-paste' examples.
Importing the XML-Data using ImportFrom-CliXML does not give the same results :-(

Expected behavior

Same as with older PWSH versions (incl. 7.5preview4)

$Object | ConvertTo-CliXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
    <TN RefId="0">
      <T>OpenCl.DeviceType</T>
      <T>System.Enum</T>
      <T>System.ValueType</T>
      <T>System.Object</T>
    </TN>
    <ToString>Gpu</ToString>
    <U64>4</U64>
  </Obj>
</Objs>

$Object | ConvertTo-Json
"Gpu"

Actual behavior

$Object | ConvertTo-CliXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
    <TN RefId="0">
      <T>OpenCl.DeviceType</T>
      <T>System.Enum</T>
      <T>System.ValueType</T>
      <T>System.Object</T>
    </TN>
    <ToString>Gpu</ToString>
    <U64>4</U64>
  </Obj>
</Objs>

$Object | ConvertTo-Json
"4"

$Object | ConvertTo-Json -EnumsAsStrings
"Gpu"

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.0-preview.5
PSEdition                      Core
GitCommitId                    7.5.0-preview.5
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions