I have thrown together a powershell script that uses the following logic:
Enter desired username?
If doesnt exist execute New-ADUser
If it does exist ........
And this is where I get stuck. If it does exist how can I ask for the user to try another username until the result is false
Heres part of the script:
$name = read-host "Enter the username" $usercheck = $null # check if username exists already in AD $usercheck = Get-ADUser -Filter {sAMAccountName -eq $name} # Check search result to see if it's Null and then create the user If ($usercheck -eq $null) { Write-Host "You can use this username" } # If it's not null, print out to screen Else { Write-Host "User: "$_.SamAccountName "already exists!"}