Do While not behaving

Welcome Forums General PowerShell Q&A Do While not behaving

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 years, 3 months ago.

  • Author
    Posts
  • #58857

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 638
    Helping Hand
    Rank: Major Contributor
     
    While ($verify -eq $false)
    
    • #58864

      Participant
      Points: 0
      Rank: Member

      *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!!

The topic ‘Do While not behaving’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort