i have two arrays $newUsers and $oldUsers already populated with userid's in the script i've written. My next goal is to check whether the userid from $newUsers exists in $oldUsers. if yes, then display statement Write-Host "New User_id $rowNew found in Old user list" else display Write-Host "New User_id $rowNew Notfound in Old user list"
below is the logic i used and the output i'am getting.
foreach ($rowNew in $newusers){
foreach ($rowOld in $oldusers){
if ($rowNew -ieq $rowOld){
Write-Host "New User_id $rowNew found in Old user list"
} else {
Write-Host "New User_id $rowNew Notfound in Old user list"
}
}
}
--Result
New User_id fadb274 found in Old user list
New User_id fadb274 Notfound in Old user list
New User_id fadb274 Notfound in Old user list
New User_id fadb274 Notfound in Old user list
New User_id fadb274 Notfound in Old user list
New User_id fadb274 Notfound in Old user list
New User_id fadb274 Notfound in Old user list
New User_id fadb274 Notfound in Old user list
New User_id fad8878 found in Old user list
New User_id fad8878 Notfound in Old user list
New User_id fad8878 Notfound in Old user list
New User_id fad8878 Notfound in Old user list
Not sure why i'am getting the above results, should'nt i be getting one result for each userid. could anyone help me as to what i need to change in code snippet above?
compare-objectcmdlet.