Comparing Two Arrays & Get the Values Which Are Not Common
I Wanted a Small Logic to Compare Contents of Two Arrays & Get the Value Which Is Not Common Amongst Them Using Powershell Example If $A1=@(1,2,3,4,5)...
i wanted a small logic to compare contents of two arrays & get the value which is not common amongst them using powershell
example if
$a1=@(1,2,3,4,5)
$b1=@(1,2,3,4,5,6)
$c which is the output should give me the value "6" which is the output of what's the uncommon value between both the arrays.
Can some one help me out with the same! thanks!
7 Answers
PS > $c = Compare-Object -ReferenceObject (1..5) -DifferenceObject (1..6) -PassThru
PS > $c
6
$a = 1..5
$b = 4..8
Must Read
$Yellow = $a | Where {$b -NotContains $_}
$Yellow contains all the items in $a except the ones that are in $b:
PS C:\> $Yellow
1
2
3