Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroupObject -AsHashTable should "core" any PSObjects being used as keys #6933

Closed
BrucePay opened this issue May 24, 2018 · 1 comment · Fixed by #7123
Closed

GroupObject -AsHashTable should "core" any PSObjects being used as keys #6933

BrucePay opened this issue May 24, 2018 · 1 comment · Fixed by #7123
Assignees
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-Fixed The issue is fixed. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Comments

@BrucePay
Copy link
Collaborator

There is a bug when using the -AsHashTable flag on Group-Object such that the keys in the hashtable are still wrapped in PSObject when added to the table. This makes them useless because you can't retrieve the entry and confusing because it looks like a string but it isn't. See this issue on StackOverflow and also this one

Steps to reproduce

$groupedProjects = 1..10 | foreach {
    [PSCustomObject]@{ ErrorMessage = if ($_ % 2) {'SomeError'} else {''} }
} |
    Group-Object -Property {if ($_.ErrorMessage) {'Failed'} else {'Successful'}} -AsHashTable
$groupedProjects.Keys
$groupedProjects["Failed"]

Expected behavior

>  $groupedProjects.Keys # the keys exist and look like strings
Successful
Failed
>  $groupedProjects.Failed # Should be able to retrieve the corresponding value

ErrorMessage
------------
SomeError
SomeError
SomeError
SomeError
SomeError
>

Actual behavior

 >  $groupedProjects.Keys
Successful
Failed
>  $groupedProjects.Failed # Specifying the key name fails because the actual key is a PSObject
>

Environment data

(This fails on all version of PowerShell)

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.2
PSEdition                      Core
GitCommitId                    v6.1.0-preview.2
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@BrucePay BrucePay self-assigned this May 24, 2018
@iSazonov iSazonov added Issue-Bug Issue has been identified as a bug in the product WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module labels May 25, 2018
@powercode
Copy link
Collaborator

Just ran into this :) Any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-Fixed The issue is fixed. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
3 participants