View Single Post
Old 08-08-2008   #1 (permalink)
RickB


 
 

How to create a hash table from an array

I'm looking for the simplest way to turn an array of custom objects
into a hashtable with some particular property of the custom object
being the key.

So, given some function that emits an array of objects

function myArray {
1..10|
%{$a=$_;""|
select-object name,even,sqr|
%{$_.name = "a$a"
$_.even = [int]($a/2)*2 -eq $a
$_.sqr = $a*$a
$_}}}

What function f will result in

PS 1> $h = f $(myArray) name
PS 2> $h.a3.even
False
My System SpecsSystem Spec