Create new AD users in batches through scripts
The basic command line for creating an AD user is as follows:
New-Aduser-Name "Test Account1"-Surname Test-Givenname Account1-Company Contoso-Country CN-Department Test-City BJ-AccountPassword (ConvertTo-SecureString-AsPlainText "Ts12345678"-Force)-Path "OU=Users,DC=contoso,DC=com"-enabled $true-UserPrincipalname testaccount1@contoso.com
Refer to the TechNet documentation:
Https://docs.microsoft.com/en-us/powershell/module/addsadministration/new-aduser?view=win10-ps
Then, set the parameters and pass in the parameter values from the Excel table:
$Users = Import-Csv-Path "C:\ Userlist-sn.csv"
Foreach ($User in $Users)
{
$Displayname = $User.Firstname + "" + $User.Lastname
$UserFirstname = $User.Firstname
$UserLastname = $User.Lastname
$UPN = $User.email
$Password = $User.Password
$depart=$User.department
New-Aduser-Name $Displayname-Surname $UserLastname-Givenname $UserFirstname-Company Contoso-Country CN-Department $depart-City BJ-AccountPassword (ConvertTo-SecureString-AsPlainText "$Password"-Force)-Path "OU=Users,OU=$depart,DC=Contoso,DC=com"-enabled $true-UserPrincipalname $UPN
}
Create a new Excel file, then run the script, and the user successfully creates it.
Script reference documentation:
Https://social.technet.microsoft.com/wiki/contents/articles/24541.powershell-bulk-create-ad-users-from-csv-file.aspx#Reference