Reputation: 63
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!
Upvotes: 6
Views: 6856
Reputation: 301187
You can try something like this:
$h | select @{ Expression = { "$($_.Keys):$($_.Values)" }; Label ="AsString" }, @{ Expression ={$_}; Label = "Hash" } -unique
| select -expand Hash
Upvotes: 9