Arrays are not strings. :-)
$Variable1 = "10.99.1.4","10.99.1.3"
$Variable2 = [PSCustomObject]@{ServerAddresses = @('10.99.1.4','10.99.1.3')} # array elements in the same order as $Variable1
$Variable3 = [PSCustomObject]@{ServerAddresses = @('10.99.1.3','10.99.1.4')} # array elements in a dufferent order to $Variable1
# Compare variables 1 and 2
if ($null -eq (Compare-Object -ReferenceObject $Variable1 -DifferenceObject $Variable2.ServerAddresses -IncludeEqual | Where-Object {$_.SideIndicator -ne '=='})){
"The two arrays are equal"
}
else{
"The two arrays are not equal"
}
# Compare variables 1 and 3
if ($null -eq (Compare-Object -ReferenceObject $Variable1 -DifferenceObject $Variable3.ServerAddresses -IncludeEqual | Where-Object {$_.SideIndicator -ne '=='})){
"The two arrays are equal"
}
else{
"The two arrays are not equal"
}