Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have been trying since this morning to add 100 users to a new AD on Server 2008.

The fields I have in a excel file are :

Surname, Forename, username, password, group (NewUser, PowerUser, SuperUser), email addresses (Not exchange just for info sake in the user details).

Following is the script, I copied from a website on someone's advise :

Script code :

---[AddUser.cmd]----
@echo off
setlocal

:: *** csv-File with the name, first name, and user name:
set UserFile=C:\Users\Administrator\Desktop\scriptusers\users1.csv

:: *** Distinguished Name of the container to add the new user to:
set UsersDN=OU=newcompany,DC=domain,DC=com

for /f "tokens=1-4 delims=," %%a in ('type "%UserFile%"') do (
  set LastName=%%a
  set FirstName=%%b
  set NewUser=%%c
  set Password=%%d
  call :process
)
goto :leave

:process
set UPN=%NewUser%@%UserDNSDomain%
set DisplayName=%LastName%, %FirstName%
set NewUserDN=CN=%NewUser%,%UsersDN%
set Password=password

echo You are about to create a new user with the following properties:
echo.
echo Username:     %NewUser%
echo Display name: %DisplayName%
echo UPN:          %UPN%
echo OU:           %UsersDN%
echo.
echo Hit ^<ctrl-c^> to stop, any other key to create the user.
pause >NUL
echo.

:: *** Test mode: Remove the "ECHO" in front of the following line to run the script for real:
dsadd user "%NewUserDN%" -samid %NewUser% -upn %UPN% -fn "%FirstName%" -ln "%LastName%" -display "%DisplayName%" -pwd "%Password%" -desc "%DisplayName%" -mustchpwd yes -disabled no

:leave

Now, I exported the excel file to csv, edited the script to my liking, but when I run it, it only adds ONE user (the first one on the csv) or it will give error on password complexity. I changed the password in the script to be complex enough but no luck.

I will be really grateful if someone could let me know how to do this step by step ; I am a novice in scripting and or understanding scripts.

Thanks and Regards AerAps

share|improve this question

3 Answers 3

You could use PowerShell. It makes this a little less painless and the script is more straight-forward. I don't remember if it's included by default in Server 2008 or not. If not, it's a feature you can install with Server Manager.

It will import the csv for you automatically. All you need to do is to be sure that the CSV has column headers. See the code below for a quick example. You can expand on dsadd command below to match what you need.

$inputFile = Import-CSV  <insert filepath here>

foreach($line in $inputFile)
{
    dsadd user -samid $line.Username -pwd $line.Password
}
share|improve this answer
    
Hi Brad.Lane, Thank you for your reply, can you please specify the dsadd command specific to my needs for adding users, username, password, email addresses ? Also, I have power shell installed on the server. Can I export a excel sheet as CSV with column headers ? its the first time I am doing and i have a deadline for this :-) Thank you ever so much –  aeraps Sep 2 '09 at 21:34
    
look up the documentation on dsadd. then add in all the options for dsadd that match up with the fields in your csv file. –  brad.lane Sep 2 '09 at 22:40

Try using csvde, good resource here, it is probably the best tool for this job.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.