I have two arrays which contain email addresses:
$from
$newuser
I want to output the value of $from
to the user but I want to color the values that are also present in the variable $newuser
.
So the output will show all email addresses in $from
in white color but show in green the ones that are present in $newuser
.
I don't want to append the values of both variables but compare the two arrays and show in green the ones that are present in both arrays.
I'm trying to do that with a IF
in a Foreach
but the output is always White.
foreach ($element in $from) {
if($element -contains $newuser) {
write-host $element `n -ForegroundColor Green
} else {
write-host $element `n -ForegroundColor White
}
}
Need some help to figure why.
Thank you!
question from:https://stackoverflow.com/questions/65944232/powershell-array-output-somes-values-with-multiple-colors