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

标签 powershell

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

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

$h = $h1,$h2,$h3

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

谢谢!

最佳答案

你可以尝试这样的事情:

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

关于powershell - 如何从powershell中的哈希表数组中获取唯一值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14332930/

相关文章:

javascript - 等效于 Powershell 中的 Javascript encodeURI?

powershell - Azure Add-AzureDisk 不工作

c# - 如何使用 dotnet 在命令行中传递参数?

azure - 如何检查 powershell 脚本是否正在 Azure 中运行

powershell - 对于VIServer和PowerCLI,如何仅在PowerShell中第一次提示输入凭据,然后存储凭据并将其用于下一次脚本运行?

windows - 使用 Ansible 关闭 SMB 1.0/CIFS 文件共享支持?

regex - 具有排除模式的 Powershell 正则表达式 (guid)

windows - 在 Visual Studio 中将 PowerShell 脚本作为构建事件运行的最简单/最短命令

powershell - 如果存在 ELSE re : values from csv

powershell - Powershell 过滤项目中项目的内在索引(例如使用Where-Object)