6

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!

1 Answer 1

9

You can try something like this:

$h | select @{ Expression = { "$($_.Keys):$($_.Values)" }; Label ="AsString" }, @{ Expression ={$_}; Label = "Hash" } -unique 
                      | select -expand Hash
Sign up to request clarification or add additional context in comments.

2 Comments

@manojlds - I don't know if it can be simplified. You can wait for some other answers ;)
Seems not to be simplified, time is running ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.