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

2 years ago.

  • Author
  • #58857

    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 (
        $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

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

      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.