'Search for user in domain AD
Working on this code for creating a new user script and I havent got much experience with if statements. I am trying to get the system to detect if the new user matches an already existing user and if it does, ask for the middle name.
$firstName = Read-Host -Prompt 'Please enter new users first name'
$lastName = Read-Host -Prompt 'Please enter new users last name'
$userName = "$firstName.$lastName"
if ($username -match -ADUser)
{
write-host "$userName is already in use"
$Selection = read-host "Would you like to add a middle name? (Y/N)"
switch ($Selection) {
'Y'{
$middleName = read-host - prompt "Please enter the users middle initial"
$userName = "$firstName.$middleName.$lastName"
}
'N' {
return
}
}
}
else{
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
