Skip to content

ConvertTo-Json does not convert additional members of nested properties #19185

@JTDotNet

Description

@JTDotNet

Prerequisites

Steps to reproduce

I am attempting to add a NoteProperty to a reference type property of an object, then convert that entire object to JSON using the ConvertTo-Json cmdlet. While this works fine when adding a NoteProperty to a top level object, if you do this to an object that's a property of the top-level object, the NoteProperty is not handled by the cmdlet:

`$foo = Get-ADUser "someUser"

$foo.SID | Add-Member -MemberType NoteProperty -Name "bar" -Value "barValue" -Force

$foo | ConvertTo-Json`

Expected behavior

Cmdlet should output:

{
  ...
  "SID": {
    "BinaryLength": 28,
    "AccountDomainSid": {
      "BinaryLength": 24,
      "AccountDomainSid": [redacted],
      "Value": [redacted]
    },
    "Value": [redacted],
    "bar": "barValue"
  },
  ...
}

Actual behavior

Output does not include additional property:

{
  ...
  "SID": {
    "BinaryLength": 28,
    "AccountDomainSid": {
      "BinaryLength": 24,
      "AccountDomainSid": [redacted],
      "Value": [redacted]
    },
    "Value": [redacted]
  },
  ...
}

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.2
PSEdition                      Core
GitCommitId                    7.3.2
OS                             Microsoft Windows 10.0.19044
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

    Resolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions