比较两个数组并排除共同的数组并显示结果

问题描述 投票:0回答:1

我的第一个数组包含一行字符串(此列表包含 456454),需要与数组(456454, 456789)进行比较。

$unprotected - “此列表包含 456454”$blocklist - @('456454', '456789')

foreach($blocklist 中的 $ele) { foreach($elem in $unprotected) { if ($ele -包含 $elem) {} 否则{$var_chk =“1”} } } if($var_chk = "1"){$Arr_lst += $elem}

arrays powershell compare
1个回答
0
投票

也许

Compare-Object
? 对于两个都不存在的每个值,它返回一个
[PSCustomObject]
数组,如果该值出现在左侧或右侧数组中,则该值和一个明确的箭头

示例:

PS > $Comparison = Compare-Object @(1;2;3;4) @(1;2;4;5)

PS > $Comparison | Format-List

     InputObject   : 5
     SideIndicator : =>
     
     InputObject   : 3
     SideIndicator : <=
© www.soinside.com 2019 - 2024. All rights reserved.