Do While not behaving

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Chris Ediger Chris Ediger 1 week, 3 days ago.

  • Author
    Posts
  • #58857
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

    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)        
           }
    
  • #58858
    Profile photo of Rob Simmers
    Rob Simmers
    Participant
     
    While ($verify -eq $false)
    
    • #58864
      Profile photo of Chris Ediger
      Chris Ediger
      Participant

      *vigorously slaps head while hanging it low*

      I stared at that all morning and couldn't figure out what the heck I was doing wrong.

      That was just the thing. Thank you!!

You must be logged in to reply to this topic.