Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Creating an account creation script to create new users in Windows Server 2008

Writer 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.

1

1 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,SamAccountName

This 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,pfischer

SamAccountName - 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 -PassThru

Account 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy