如何从PowerShell中的哈希表数组中获取唯一值?

ycy*_*ang 4 powershell

如何从PowerShell中的哈希表数组中获取唯一值?

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

$h = $h1,$h2,$h3
Run Code Online (Sandbox Code Playgroud)

我想从$ h中删除重复值($ h1或$ h3).

谢谢!

man*_*lds 5

你可以尝试这样的事情:

$h | select @{ Expression = { "$($_.Keys):$($_.Values)" }; Label ="AsString" }, @{ Expression ={$_}; Label = "Hash" } -unique 
                      | select -expand Hash
Run Code Online (Sandbox Code Playgroud)