Group-Object -Ashashtable for string values - by stej

Status : 


Sign in
to vote
ID 772015 Comments
Status Active Workarounds
Type Bug Repros 0
Opened 11/23/2012 12:17:52 AM
Access Restriction Public


Several times I found out that Group-Object doesn't behave the same way for strings and the other objects. Compare:

$x ='1', 'abc', 'text' | Group-Object -AsHashTable
$x.containsKey('1')            # returns false
$x['1'] -ne $null                 # returns false


$x = 1,2,3,2 | Group-Object -AsHashTable
$x.containsKey(2)            # returns true
$x[2]                                # returns the array

Futhermore when I just output 
'1', 'abc', 'text' | Group-Object -AsHashTable
to the console, it looks like standard hashtable:
  Name                           Value
  ----                           -----
  text                           {text}
  abc                            {abc}
  1                                {1}

Keys collection contains '1', but the hashtable does not:
('1', 'abc', 'text' | Group-Object -ashashtable).keys -contains '1'   #returns true
('1', 'abc', 'text' | Group-Object -ashashtable)['1']                         #returns $null

I'm running V2, maybe on V3 it is alredy fixed.. I have no chance to test it.
Sign in to post a comment.