I have an array of string values and am trying to run a loop to match (using -eq operator) and return true if another variable matches one of the string values in the array. Even though I know the values should match, the loop is returning false.
I am currently taking the PS objects and pulling out the string values of a particular property of the object for the matching. I tried other operators aside from -eq, including -like using a wildcard and -match but there is no change in behavior. I also am currently constructing a list using $XXXX.Add($XXXX), but also had no luck with just populating an array with =+.
foreach ($Server in $UpdateGroupMembers) {
if ($Server -eq $NodeName) {
Write-Host "$Server is a match, loop terminated"
return $true
#break
} else {
Write-Host "There is no match"
return $false
}
}
$NodeName in the code above is a value that I know exists in the array/list, so I am quite lost.
$list = 'one','two','three'; $target = 'two'; foreach ($i in $list) { $i -eq $target }$NodeName.return $truespecifically and not just$true?returndoes exactly what the name suggests.