PowerShell / PowerShell/PowerShell

`ConvertTo-Json` neglects to serialize ETS properties when passed output from CDXML cmdlets (CIM instances) that isn't `[psobject]` wrapped by argument

Open
#24,554 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs-Triage WG-Cmdlets WG-NeedsReview
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

Prerequisites
Steps to reproduce

Note:

  • This is yet another manifestation of https://github.com/PowerShell/PowerShell/issues/5579

  • Note that the problem only arises for CDXML cmdlets that do not themselves wrap their output objects in [psobject], such as Get-PhysicalDisk, Get-VirtualDisk, and Get-Volume; others, such as Get-Disk, do perform this wrapping.

# Note: Since objects passing through the pipeline are automatically [psobject]-wrapped, the following
#   pipeline alternative works correctly:         
#    Get-PhysicalDisk | ConvertTo-Json 3>$null | ConvertFrom-Json | Format-List
ConvertTo-Json (Get-PhysicalDisk) 3>$null | ConvertFrom-Json | Format-List
Expected behavior
CimClass                         : @{CimSuperClassName=MSFT_StorageFaultDomain; CimSuperClass=; CimClassProperties=System.Object[]; CimClassQualifiers=System.Object[];
                                   CimClassMethods=System.Object[]; CimSystemProperties=}
CimInstanceProperties            : {@{Name=ObjectId; Value={1}\\MKW11\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk.ObjectId="{47519af7-9162-11ee-9dc0-806e6f6e6963
                                   }:PD:{f2881886-c54b-46f7-c1ac-8eb641e316de}"; CimType=14; Flags=35688452; IsValueModified=False}, @{Name=PassThroughClass; Value=; CimType=14;
                                   Flags=572522500; IsValueModified=False}, @{Name=PassThroughIds; Value=; CimType=14; Flags=572522500; IsValueModified=False},
                                   @{Name=PassThroughNamespace; Value=; CimType=14; Flags=572522500; IsValueModified=False}…}
CimSystemProperties              : @{Namespace=root/microsoft/windows/storage; ServerName=MKW11; ClassName=MSFT_PhysicalDisk; Path=}
ClassName                        : MSFT_PhysicalDisk
Usage                            : Auto-Select
OperationalStatus                : OK
# ... remaining properties omitted for brevity.
Actual behavior
CimClass              : @{CimSuperClassName=MSFT_StorageFaultDomain; CimSuperClass=; CimClassProperties=System.Object[]; CimClassQualifiers=System.Object[];
                        CimClassMethods=System.Object[]; CimSystemProperties=}
CimInstanceProperties : {@{Name=ObjectId; Value={1}\\MKW11\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk.ObjectId="{47519af7-9162-11ee-9dc0-806e6f6e6963}:PD:{f2881
                        886-c54b-46f7-c1ac-8eb641e316de}"; CimType=14; Flags=35688452; IsValueModified=False}, @{Name=PassThroughClass; Value=; CimType=14; Flags=572522500;
                        IsValueModified=False}, @{Name=PassThroughIds; Value=; CimType=14; Flags=572522500; IsValueModified=False}, @{Name=PassThroughNamespace; Value=; CimType=14;
                        Flags=572522500; IsValueModified=False}…}
CimSystemProperties   : @{Namespace=root/microsoft/windows/storage; ServerName=MKW11; ClassName=MSFT_PhysicalDisk; Path=}

That is, only the type-native properties were serialized, not also the ETS (adapted) ones.

Error details

No response

Environment data
PowerShell 7.5.0-preview.5 on Windows (also affects Windows PowerShell)
Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the ConvertTo-Json (Get-PhysicalDisk) example and compare it with the pipeline form. Investigate the ConvertTo-Json serialization path for CIM instances that are not [psobject]-wrapped. Done means ETS properties such as Usage and OperationalStatus appear alongside the type-native properties in the serialized output.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.