Return casesensitive hashtable with Group-Object
See original GitHub issueSteps 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 -CaseSensitive
Expected 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Group-Object (Microsoft.PowerShell.Utility)
Group-Object returns a table with one row for each property value and a column that ... and AsHashtable parameters to create a case-sensitive...
Read more >Is there any way to convert case-sensitive hashtable into ...
It's not possible to convert a case-sensitive hash table into a case-insensitive one, the way around it is to recreate it:
Read more >Group-Object - PowerShell
To create a calculated, property, create a hash table with an Expression key that specifies a string or script block value. -caseSensitive Make...
Read more >Exploring Group-Object in PowerShell | How
Beginning in PowerShell 7, Group-Object can combine the CaseSensitive and AsHashtable parameters to create a case-sensitive hash table. The hash ...
Read more >Group-Object - PowerShell Command - PDQ
Indicates that this cmdlet returns the group as a hash table. The keys of the hash table are the property values by which...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Grouping happens by property value, not name, and given that omitting
-AsHashtable
already 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
-CaseSensitive
with-AsHashtable
will have to be aware that the resulting hashtable will have case-sensitive key lookups, unlike regular PowerShell hashtables, but since-CaseSensitive
is an explicit opt-in, that seems reasonable.I mean, if
-CaseSensitive
doesn’t already make it explicit, we’re kind of out of options for making it explicit. 😂