Creating an account creation script to create new users in Windows Server 2008
Emily Wong
I need to be able to make an account creation script that will create a new user in the Domain Users group, set its password, roaming profile, and login script. The input will be first name, last name, username, and password. This script should read from a file formatted as such: firstname,lastname,username,password It should also be capable of inputting any number of users in the file.
11 Answer
The easiest way it to use powershell for that. You need to create CSV file with data in the following order (important!):
Name,GivenName,Surname,SamAccountNameThis can be a header line and data for each user should be added line by line in the same order like:
Arno Bost,Arno,Bost,abost,
Peter Fischer,Peter,Fischer,pfischerSamAccountName - is a username that a new user will use to login to Windows. Name - is a display name of the user.
The following script first reads the CSV file and pipes its contents into the New-ADUser cmdlet, then sets the password for each user account as Pa$$w0rd, and finally enables the accounts:
Import-Module ActiveDirectory
Import-Csv C:\data\new-users.csv | New-ADUser -Path "CN=Users,DC=yourdomain,DC=COM" -AccountPassword (ConvertTo-SecureString "Pa$$w0rd" -AsPlainText -force) -Enabled $True -ScriptPath logonscript.bat -ProfilePath \\server\folder -PassThruAccount will be enabled when created. -ScriptPath logonscript.bat shows the name of the logon script on the AD controller, -ProfilePath \server\folder is a path for the roaming profile.
Do not forget to change "CN=Users,DC=yourdomain,DC=COM" to the real domain and to the real OU where you need to store the account, e.g. "OU=office,CN=Users,DC=cooldomain,DC=COM"
Change the password "Pa$$w0rd" to what you need.
1