Repository navigation
Closed
Labels
Breaking-Changebreaking change that may affect usersIssue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues
Description
Steps to reproduce
I know PowerShell is mostly case insensitive, but when using both -AsHashTable and -CaseSensitive I expected to end up with a case sensitive hashtable.
$capitonyms = @(
[PSCustomObject]@{
Capitonym = 'Bill'
}
[PSCustomObject]@{
Capitonym = 'bill'
}
)
$capitonyms | Group-Object Capitonym -AsHashTable -CaseSensitiveExpected behavior
Name Value
---- -----
Bill {@{Capitonym=Bill}}
bill {@{Capitonym=bill}}
Actual behavior
Group-Object : The objects grouped by this property cannot be expanded because there is a key duplication. Provide a valid value for the property, and then try again.
At line:1 char:15
+ $capitonyms | Group-Object Capitonym -AsHashTable -CaseSensitive
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Group-Object], Exception
+ FullyQualifiedErrorId : The objects grouped by this property cannot be expanded because there is a key duplication. Provide a valid value for the property, and then try again.,Microsoft.PowerShell.Commands.GroupObjectCommand
Environment data
Name Value
---- -----
PSVersion 7.0.0-preview.3
PSEdition Core
GitCommitId 7.0.0-preview.3
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Reacted by HumanEquivalentUnit, Michael Klement and Mike Campbell
Metadata
Metadata
Assignees
Labels
Breaking-Changebreaking change that may affect usersIssue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues
Activity
SteveL-MSFT commentedon Aug 24, 2019
Seems completely reasonable to me.
BrucePay commentedon Aug 29, 2019
Steve Lee (@SteveL-MSFT) This would be a breaking change. If there are no key conflicts, current users may depend on the case-insensitivity of the generated hashtable. (Also note - since this cmdlet was envisioned as grouping objects by .NET property name, the notion of two properties with the same name differing by case is not the common case.)
lahell (@lahell) Given that this is a breaking change, what is the rational for doing this? That is, what scenarios are unblocked, what important thing can you do that you couldn't do before? Providing these scenarios helps the Committee make decisions about this sort of thing. Thanks!
lahell commentedon Aug 29, 2019
Why would anyone use both CaseSensitive and AsHashTable if they need a case insensitive hashtable?
I noticed this when grouping AD users by department to look for typos and was not sure if this was intentional behaviour.
This is not a big deal for me. I got the hashtable I needed with the following code.
SteveL-MSFT commentedon Aug 29, 2019
Agree with Bruce Payette (@BrucePay) that it would be good to understand what the real world scenario that is impacted by this. However, this doesn't have to be a breaking change, it could be a new switch to make it explicit.
vexx32 commentedon Aug 30, 2019
I mean, if
-CaseSensitivedoesn't already make it explicit, we're kind of out of options for making it explicit. 😂mklement0 commentedon Aug 30, 2019
Grouping happens by property value, not name, and given that omitting
-AsHashtablealready works exactly as advertised:so should the variant with
-AsHashtable.So I don't see a breaking change here, only a bug fix.
Users who opt for combining
-CaseSensitivewith-AsHashtablewill have to be aware that the resulting hashtable will have case-sensitive key lookups, unlike regular PowerShell hashtables, but since-CaseSensitiveis an explicit opt-in, that seems reasonable.lahell commentedon Aug 30, 2019
My real world scenario was just using it to clean up human errors in department names.
I guess this could be more of an issue on Linux. This simple test ends in key duplication error.
lahell commentedon Nov 22, 2019
Thanks Rain Sallow (/u/ta11ow) (@vexx32), I ran a few tests in preview 6 and your fix works great.
I did notice that adding a
$nullto the mix gives a misleading error message.The code above will throw the error message:
The InnerException is:
iSazonov commentedon Nov 22, 2019
lahell (@lahell) Please open new issue.