Sre*_*ree 4 powershell scripting powershell-3.0
我刚刚开始使用 powershell。我有两个列表,每个列表有 132 条记录和 134 条记录。它们有 85 条共同记录,我想获取单独列表中的 list1 中但不在 list2 中的值(例如 list_out1),以及另一个列表中的 list2 但不在 list1 中的值(例如 list_out2)。我终于想打印list_out1和list_out2。我尝试按照此答案中给出的方式执行操作,但在尝试打印 list_out1 时它为我提供了 list1 中的所有值。另外,我尝试使用 foreach 循环和 if 条件如下,它还为我提供了 list1 中的所有值来打印 list_out1。
foreach ($i in $list1)
{
if($list2 -notcontains $i) {
$i
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道我哪里做错了。这个逻辑对我来说似乎没问题。如果我错了请纠正我。
使用就是Compare-Object你所追求的。假设你这样做$List1.Item或类似的事情。
$MissingGroups = Compare-Object -ReferenceObject ($List1) -DifferenceObject ($List2) -Property Item | Where-Object{$_.sideIndicator -eq "<="}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14994 次 |
| 最近记录: |