powershell - Get hashtable value by key of group object under strict mode version 2? -


the following script, pivot array list x , y, doesn't work. ($hashvariable.x not working). how rewrite it? seems it's not easy simple value key in hashtable under strict mode.

set-strictmode -version 2 # change 2 1 work  $a = @('a','b','x',10),       @('a','b','y',20),       @('c','e','x',50),       @('c','e','y',30)  $a | %{      new-object psobject -prop @{"label" = "'$($_[0])','$($_[1])'"; value=@{ $_[2]=$_[3]}}  } |  group label | % {     "$($_.name), $($_.group.value.x), $($_.group.value.y)" # error     #"$($_.name), $($_.group.value['x']), $($_.group.value['y'])" # empty x,y }  

expected result.

 'a','b', 10, 20 'c','e', 50, 30 

error:

 property 'x' cannot found on object. make sure exists. @ line:6 char:35 +     "[$(@($_.name -split ",") + @($_.group.value.x, $_.group.value.y))]" +                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + categoryinfo          : notspecified: (:) [], propertynotfoundexception     + fullyqualifiederrorid : propertynotfoundstrict 

not sure want, best guess. should accumulate objects in 1 group in single hashtable object instead of creating separate hashtable each input object:

$a = ('a','b','x',10),       ('a','b','y',20),       ('c','e','x',50),       ('c','e','y',30)  $a | group-object {$_[0]},{$_[1]} | select-object values,               @{                   name='group'                   expression={                       $_.group |                       foreach-object {$t=@{}}{$t.add($_[2],$_[3])}{$t}                   }               } | foreach-object {     '''{0}'',''{1}'', {2}, {3}'-f@($_.values;$_.group['x','y']) } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -