vendredi 12 avril 2019

jumping back to the first IF statement if result is invalid

how can i improve my code to jump back to the first IF Statement if no choices are valid? basically i'm just trying to write a script that checks whether a username exists in AD or not but i want the script to jump back to the first IF statement when a bad username is given to give the user another try.

this is my code

Import-Module Activedirectory 

$name = Read-Host 'Enter Name'
if($user = get-aduser -Filter "samaccountname -eq '$name'"){
Write-Host 'Found user as "SamAccountName"'
}elseif($user = get-aduser -Filter "name -eq '$name'"){
Write-Host 'Found user as "Name"'
 } else {
Write-Host 'not found'

}
$user

would the better choice be do/while,Until ?

thank you

Aucun commentaire:

Enregistrer un commentaire