Compare powershell arrays
$a=@("a", "b", "c")
$b=@("x", "y", "z", "c", "u", "p", "i", "a");
$c=@("a", "b", "c")
$d=@("d", "e", "f")
$a
Write-Host "----"
$b
Write-Host "----"
$aUnique = Compare-Object $a $b | Where-Object {$_.SideIndicator -eq "<="}
$bUnique = Compare-Object $a $b | Where-Object {$_.SideIndicator -eq "=>"}
Write-Host "Items in a, but not in b"
$aUnique| ForEach-Object { $_.InputObject }
Write-Host "Items in b, but not in a"
$bUnique| ForEach-Object { $_.InputObject }
Write-Host "--Both arrays are the same, result is null--"
$result = Compare-Object $a $c | Where-Object {$_.SideIndicator -eq "<="}
$result -eq $null
$result.Length
Write-Host "--Arrays are not overlapping, result is object--"
$result = Compare-Object $a $d | Where-Object {$_.SideIndicator -eq "<="}
$result
$result.length -eq $a.Length
a
b
c
----
x
y
z
c
u
p
i
a
----
Items in a, but not in b
b
Items in b, but not in a
x
y
z
u
p
i
--Both arrays are the same, result is null--
True
--Arrays are not overlapping, result is object--
InputObject SideIndicator
----------- -------------
a <=
b <=
c <=
True
----