My script for creating a User:
My problem is in $ SAM, because the "name" attribute in my TXT file is the full name and I would like to create the login User with the first name plus the initials of other names.
example:
Adriano-SA
Adriano Souza Pires
=====================================================================
Import-Module ActiveDirectory
$Users = Import-Csv -Delimiter ";" -Path "C:\Users\Joan\Documents\Users.txt"
foreach ($User in $Users)
{
$OU = "OU=SE,DC=icaro,DC=br"
$Password = $User.Password
$Office = $User.Matricula
$Detailedname = $User.name
$SAM = $User.name.Substring(0,4) + "-" + $Users.Name.Substring(5,1)
"Criando Usuario: $Detailedname"
New-ADUser -Name $Detailedname -Office $Office -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -GivenName $user.Name -Surname $user.Name -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force)
-Enabled $true -Path $OU
}
===================================================
File TXT:
Name;Matricula;PasswordJean Carlos Araujo;99999900;s3nh@senh@
Adriano Souza Pires;99999900;s3nh@senh@