Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 比较数组时删除匹配项_Arrays_Powershell_Compare_Powershell 4.0 - Fatal编程技术网

Arrays 比较数组时删除匹配项

Arrays 比较数组时删除匹配项,arrays,powershell,compare,powershell-4.0,Arrays,Powershell,Compare,Powershell 4.0,我想帮助比较两个数组,比如用户,并抛出两个数组中存在的或匹配的任何用户,然后将结果放入最终数组。例如: ###define arrays $array1 = @("bill","eric","james","sarah") $array2 = @("bill","scott","sarah","nancy") ###Combine/Filter? arrays and remove users that exist in both arrays $result = ($array1 + $ar

我想帮助比较两个数组,比如用户,并抛出两个数组中存在的或匹配的任何用户,然后将结果放入最终数组。例如:

###define arrays
$array1 = @("bill","eric","james","sarah")
$array2 = @("bill","scott","sarah","nancy")

###Combine/Filter? arrays and remove users that exist in both arrays
$result = ($array1 + $array2 | some fancy match removal goes here)
$result
eric,james,scott,nancy
我想确保在合并时两个数组中的匹配项都被完全删除。因此,如果两个数组中都存在“sarah”,我想将其从最终结果中完全删除。可能吗?

用于提取两个源阵列中唯一的元素:

$result = Compare-Object $array1 $array2 | Select-Object -Expand InputObject

这太棒了,非常感谢你的帮助