I am currently in the process of setting up an AD user creation script with questions.
After answering all the questions here is the error that appears.
New-ADUser: An attribute value was not within the acceptable range At character E: \ SCRIPT \ SCRIPT_CREATE_USER_QUESTION.ps1: 17: 5
- New-ADUser -SamAccountName $ Username `
The original code is : `Import-Module ActiveDirectory
$Prenom = Read-Host "Merci de rentrer le prénom de l'utilisateur à créer "
$Nom = Read-Host "Merci de rentrer le nom de l'utilisateur à créer "
$Password = Read-Host "Merci de rentrer le mot de passe en respectant la politique actuel "
$Description = Read-Host "Merci de rentrer l'intitulé du poste "
$FirstLetter = $Prenom.Substring(0,1).ToLower()
$TwoLetter = "$Prenom.Substring(0,2)"
$FirstLetterName = "$Nom.Substring(0,1)"
$NomMinuscule = $Nom.ToLower()
$Username = "$FirstLetter$NomMinuscule"
$Init = "$TwoLetter$FirstLetterName.ToUpper()"
$Chemin = "OU=LBC-USERS,DC=lbcdom,DC=local"
New-ADUser -SamAccountName $Username `
-UserPrincipalName "[email protected]" `
-Name "$Prenom $Nom" `
-GivenName $Prenom `
-Surname $Nom `
-Enabled $True `
-DisplayName "$Nom, $Prenom" `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force) `
-Description $Description `
-Initials $Init `
-EmailAddress "[email protected]" `
-ProfilePath "\\SRV-WINLBC\Profils_itinerants\$Username" `
-Path $Chemin `
-ChangePasswordAtLogon $false `
-PasswordNeverExpires $true `
-CannotChangePassword $true
Write-Warning "Bravo! L'utilisateur : $Username est cree."`
initialsattribute must be no longer than 6 characters. Your$Initvariable likely has the literal valueFirstName.Substring(0,2)FullName.Substring(0,1).ToUpper()because of the way you've constructed your strings