Skip to content

Group-Object fails with a NullReferenceException on empty noteproperty  #3300

@SteveL-MSFT

Description

@SteveL-MSFT

Repro:

PS C:\Users\slee> $x = 1 | Select-Object -Property @{Name = 'X'; Expression = {}}
PS C:\Users\slee> $x | Group-Object X

Expected

Count Name                      Group
----- ----                      -----
    1                           {@{X=}}

Actual

Group-Object : Object reference not set to an instance of an object.
At line:1 char:6
+ $x | Group-Object X
+      ~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Group-Object], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GroupObjectCommand

Workaround

PS C:\Users\slee> $x = 1 | Select-Object -Property @{Name = 'X'; Expression = {$null}}
PS C:\Users\slee> $x | Group-Object X

Count Name                      Group
----- ----                      -----
    1                           {@{X=}}

TFS:10939589

PSVersionTable

PS C:\Users\slee> $psversiontable

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions