1 | initial version |
To check for duplicate values in PowerShell when comparing two arrays, you can use the Compare-Object
cmdlet along with the -IncludeEqual
parameter. Here's an example:
$array1 = 1, 2, 3, 4, 5
$array2 = 4, 5, 6, 7, 8
# Compare the two arrays and include equal items
$duplicates = Compare-Object $array1 $array2 -IncludeEqual | Where-Object {$_.SideIndicator -eq '=='}
# Output the duplicate values
$duplicates.InputObject
In this example, the output would be:
4
5
This means that 4
and 5
are the duplicate values between the two arrays.