The basic command line for creating AD users is tested 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 [email protected]
Refer to the TechNet documentation:
Https://docs.microsoft.com/en-us/powershell/module/addsadministration/new-aduser?view=win10-ps
Then, set the parameters to tell the parameter values to be passed in from the Excel table:
$Users? =? Import-csv?-path? " C:\Userlist-sn.csv "????????????
Foreach? ($User? $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, and then run the script that the user created successfully.
Script reference Documentation:
https://social.technet.microsoft.com/wiki/contents/articles/24541. Powershell-bulk-create-ad-users-from-csv-file.aspx#reference
Batch new ad user by script