Author Posts

November 28, 2016 at 5:42 pm

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)        
       }

November 28, 2016 at 6:01 pm

 
While ($verify -eq $false)

November 28, 2016 at 6:10 pm

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