Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get unique value from an array of hashtable in powershell?

Tags:

powershell

how to get unique value from an array of hashtable in powershell?

$h1 = @{a=1;b=2};
$h2 = @{a=3;b=4};
$h3 = @{a=1;b=2};

$h = $h1,$h2,$h3

I want to remove duplicate value ($h1 or $h3) from $h.

thanks!

like image 334
ycyang Avatar asked Jan 15 '13 07:01

ycyang


1 Answers

You can try something like this:

$h | select @{ Expression = { "$($_.Keys):$($_.Values)" }; Label ="AsString" }, @{ Expression ={$_}; Label = "Hash" } -unique 
                      | select -expand Hash
like image 188
manojlds Avatar answered Sep 29 '22 09:09

manojlds