Script trying to check to see if user input exists in a list of AD user samaccountnames. The scripts seems to ignore the while ($verify=$false). It works when the user input exists in the list but not when it doesn’t
function Reset-UserPassword { param ( [string]$userlastname ) $selectname = Get-ADUser -Filter {surname -eq $userlastname} -Properties samaccountname,office,CN if ($selectname.count -gt 1) { Write-Host "There are multiple users with that name." -ForegroundColor yellow $multipleusers = $selectname.samaccountname $selectname | Select-Object @{n='Name';e={$_.CN}},@{n='Logon Name';e={$_.SamAccountName}} | Format-List Do { $selectname = Read-Host "Please enter Logon Name from above" if ($multipleusers -notcontains $selectname) { $verify = $false Write-Host "Name not listed" } elseif ($multipleusers -contains $selectname) { $verify = $true } } While ($verify = $false) }