We help IT Professionals succeed at work.

Create users from a file

598 Views
Last Modified: 2008-04-24
Hi,

I want to create test users as test1,test2,test3 on my ads.How can i create users from a file.Can i have a script for this.

REgards
Sharath
Comment
Watch Question

Commented:
Hi Bsharath,

Probably the easiest way to do this is with LDIFDE Utility.

Go Here for a step by step guide on to do it. ->
http://www.microsoft.com/technet/prodtechnol/windows2000serv/technologies/activedirectory/howto/bulkstep.mspx

Author

Commented:
Can i have a simple command on this.TO create a user test.Can you please give me the script line.
Toni UranjekConsultant/Trainer

Commented:
Hi!

This is command line:
FOR /F %i in (users.txt) DO NET USER %i P@ssw0rd /domain /ADD

Users should be in users.txt, they will all have "P@ssw0rd" set as password.

HTH

Toni

Author

Commented:
toniur:

Thanks this is creating the user but no firstname,last name and full name...
Toni UranjekConsultant/Trainer

Commented:
Well, this was not part of your question! If you have more data in your file you should specify what kind of data is in your file and how it is organized.

Author

Commented:
I can raise a new question for this can you help me on this...:).So that i can raise a new question and close this question..
Toni UranjekConsultant/Trainer

Commented:
There is no need to open new question, but you should provide more details what is in your users.txt file exactly or nobody can coma up with solution.

Author

Commented:
EmpId      ExtNo      Building      SeatNo      DepartmentName      NT Login      E-Mail Address      Location        

EMP ID has to be in the desription box..
Toni UranjekConsultant/Trainer

Commented:
There is no easy way to do this, the way your data is organized. And I know you're on the hunt for simple solutions. The closest you will get is to use CSVDE. But first your data has to be reformated.  I can not link all your properties to user account properties. What is SeatNo, Building?
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
* Following script require Accounts.txt file on C: drive root.
* Accounts.txt file *MUST* have all the following information separated with comma (,)
a) First Name
b) Last Name
c) NT Login
d) EmpId
e) ExtNo
f) Building
g) SeatNo
h) Department Name
i) E-Mail Address
j) Location

Like:
Farhan,Kazi,FKazi,0849,117,Business Avenue,02,ITS,xxx-at-xxx.com,JDK

* You also need to set 'OUDomain' variable's value with users defualt OU and Domain.
Like:
SET OUDomain=OU=InfoTec,DC=Training,DC=Com

* Copy and Paste following code in notepad and save it with any name having .bat extension.

:: Batch Script Start

:: a) -FN      = First Name
:: b) -LN      = Last Name
:: c) -SAMID   = NT Login
:: d) -Desc    = EmpId
:: e) -Tel     = ExtNo
:: f) -Office  = Building
:: g) -Office  = SeatNo
:: h) -Dept    = Department Name
:: i) -Email   = E-Mail Address
:: j) -Company = Location

@Echo Off
SETLOCAL

IF NOT EXIST C:\Accounts.txt Goto ShowErr

SET OUDomain=OU=InfoTech,DC=Training,DC=Com
FOR /F "delims=, tokens=1-10" %%a IN (C:\Accounts.txt) Do (
      DSAdd User "CN="%%a" "%%b",%OUDomain%" -SAMID "%%c" -FN "%%a" -LN "%%b" -Display "%%a %%b" -Desc "%%d" -Tel "%%e" -Office "%%f SeatNo: %%g" -Dept "%%h" -Email "%%i" -Company "%%j" -Disabled No
)

Goto End
:ShowErr
Echo 'C:\Accounts.txt' File not found.
:END
:: Batch Script End

Author

Commented:
For which user will these details update.
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
It will CREATE users from the information provided in C:\Accounts.txt file.

Author

Commented:
I get this.

dsadd failed:CN=Testing xxx,OU=Named Accounts,OU=User Accounts,OU=IND,OU=Count
ries,DC=Development,DC=Group,DC=co,DC=uk:The parameter is incorrect.
type dsadd /? for help.Press any key to continue . . .
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
User cannot be added in multiple OU's.
Can you please show me what you have in Accounts.tx file?

Author

Commented:
I want to add the user in Named OU only.This is the full path that i have given.

In the txt file i have this.

Testing,india,testingi,0078,8694,hc,2f-45,testing@plc.com,India


Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
You need to modify following line inside the script.
SET OUDomain=OU=InfoTec,DC=Training,DC=Com
Like:
SET OUDomain=OU=Named,DC=DEVELOPMENT,DC=GROUP,DC=CO,DC=UK

Check following (Department Name is missing)
a) First Name        = Testing
b) Last Name       = india
c) NT Login             = testingi
d) EmpId             = 0078
e) ExtNo             = 8694
f) Building              = hc
g) SeatNo             = 2c-45
h) Department Name       = ???              <--- Missing
i) E-Mail Address       = testing@plc.com
j) Location India      = India

Author

Commented:
I get this now.

dsadd failed:CN=Testing i,OU=Named Accounts,OU=User Accounts,OU=IND,OU=Count
ries,DC=Development,DC=Group,DC=co,DC=uk:Unable to update the password. The
 value provided for the new password does not meet the length, complexity, or hi
story requirement of the domain.
type dsadd /? for help.Press any key to continue . . .

Where should i specify the password.
Toni UranjekConsultant/Trainer

Commented:
Password can be specified in script, just add -pwd switch to dsadd command:

DSAdd User "CN="%%a" "%%b",%OUDomain%" -SAMID "%%c" -FN "%%a" -LN "%%b" -Display "%%a %%b" -Desc "%%d" -Tel "%%e" -Office "%%f SeatNo: %%g" -Dept "%%h" -Email "%%i" -Company "%%j" -Disabled No -pwd P@ssw0rd


Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
* Accounts.txt file *MUST* have all 11 fields the following information separated with comma (,)
* Given password complexity should be as per policy defined in AD
Like:
Farhan,Kazi,FKazi,0849,117,Business Avenue,02,ITS,xxx-at-xxx.com,JDK,P@ssw0rd

:: Batch Script Start
:: a) -FN          = First Name
:: b) -LN          = Last Name
:: c) -SAMID   = NT Login
:: d) -Desc     = EmpId
:: e) -Tel         = ExtNo
:: f) -Office    = Building
:: g) -Office    = SeatNo
:: h) -Dept       = Department Name
:: i) -Email       = E-Mail Address
:: j) -Company = Location
:: k) -pwd     = password

@Echo Off
SETLOCAL

IF NOT EXIST C:\Accounts.txt Goto ShowErr

SET OUDomain=OU=InfoTech,DC=Training,DC=Com
FOR /F "delims=, tokens=1-10" %%a IN (C:\Accounts.txt) Do (
      DSAdd User "CN="%%a" "%%b",%OUDomain%" -SAMID "%%c" -FN "%%a" -LN "%%b" -Display "%%a %%b" -Desc "%%d" -Tel "%%e" -Office "%%f SeatNo: %%g" -Dept "%%h" -Email "%%i" -Company "%%j" -pwd %%k -Disabled No
)

Goto End
:ShowErr
Echo 'C:\Accounts.txt' File not found.
:END
:: Batch Script End

Author

Commented:
This is going really great.I have been search a way for months and just got it.

Need some more additions :)

1. password never expires has to be checked.
2. In Account > Userlogon Name has to be entered as Firstname and lastname first character
ex: Sharath reddy (Should be as) Sharathr
3. An intimation report after creation to a file.With all the things the script has done.

THX
Sharath

Author

Commented:
Where will the Mailbox be created.I have different Storage groups.?
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
=> Accounts.txt file *MUST* have following 10 fields all separated with comma (,)
1)  First Name
2)  Last Name
3)  EmpId
4)  ExtNo
5)  Building
6)  SeatNo
7)  Department Name
8)  E-Mail Address
9)  Location
10) Password

=> Given password complexity should be as per policy defined in AD
Like:
Farhan,Kazi,0849,117,Business Avenue,02,ITS,xxx-at-xxx.com,JDK,P@ssw0rd

=> Script will generate NewAccReport.txt file on C: drive root.

:: Batch Script Start
:: a) -FN      = First Name
:: b) -LN      = Last Name
:: c) -Desc     = EmpId
:: d) -Tel      = ExtNo
:: e) -Office      = Building
:: f) -Office      = SeatNo
:: g) -Dept      = Department Name
:: h) -Email      = E-Mail Address
:: i) -Company = Location
:: j) -pwd           = password

@Echo Off
setlocal enabledelayedexpansion
IF NOT EXIST C:\Accounts.txt Goto ShowErr

SET OUDomain=OU=Accounts,DC=Training,DC=Com
FOR /F "delims=, tokens=1-10" %%a IN (C:\Accounts.txt) Do (
      set F=%%a
      set L=%%b
      set ID=!F!!L:~0,1!
      Echo Creating user !ID!
      DSAdd User "CN="%%a" "%%b",%OUDomain%" -SAMID "!ID!" -FN "%%a" -LN "%%b" -Display "%%a %%b" -Desc "%%c" -Tel "%%d" -Office "%%e SeatNo: %%f" -Dept "%%g" -Email "%%h" -Company "%%i" -pwd %%j -Disabled No -PwdNeverExpires Yes >>C:\NewAccReport.txt
)      

Goto End
:ShowErr
Echo 'C:\Accounts.txt' File not found.
:END
ENDLOCAL
:: Batch Script End

Author

Commented:
I get this.

Creating user SindhuR
dsadd failed:No value specified for `pwd'.
type dsadd /? for help.Press any key to continue . . .


Have you updated these.

1. password never expires has to be checked.
2. In Account > Userlogon Name has to be entered as Firstname and lastname first character
ex: Sharath reddy (Should be as) Sharathr
3. An intimation report after creation to a file.With all the things the script has done
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Show me what you have inside Accounts.txt file.

Author

Commented:
This is what i have

Sindhu,Reddy,1809,9840130004,House,HR,sindhur@domainname.com,Perungudi,abc123
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Sindhu,Reddy,1809,9840130004,House,HR,sindhur@xxxplc.com,Perungudi,abc123
Above line contains 9 fields and script requirement is 10 fields!!!
1)  First Name      = Sindhu
2)  Last Name      = Reddy
3)  EmpId            = 1809
4)  ExtNo            = 9840130004
5)  Building             = House
6)  SeatNo            = ??????              <---- Missing
7)  Department Name      = HR
8)  E-Mail Address      = sindhur@xxxplc.com
9)  Location            = Perungudi
10) Password      = abc123

Before posting my script I use to test it at my end and after its successful operation I post it here.
Please read the instruction provided with the script and provide all the information that is required to run this script.

Author

Commented:


Every thing looks fine

2. In Account > Userlogon Name has to be entered as Firstname and lastname first character
ex: Sharath reddy (Should be as) Sharathr
The userlogon name is not been created.

When i try to login useing these credentials

Username Sindhur
password abc123

User account not found but in ads i am able to see the user.
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Check following script.

:: Batch Script Start
:: a) -FN      = First Name
:: b) -LN      = Last Name
:: c) -Desc    = EmpId
:: d) -Tel     = ExtNo
:: e) -Office  = Building
:: f) -Office  = SeatNo
:: g) -Dept    = Department Name
:: h) -Email   = E-Mail Address
:: i) -Company = Location
:: j) -pwd     = password

@Echo Off
setlocal enabledelayedexpansion
IF NOT EXIST C:\Accounts.txt Goto ShowErr

SET OUDomain=OU=Accounts,DC=Training,DC=Com
FOR /F "delims=, tokens=1-10" %%a IN (C:\Accounts.txt) Do (
      set F=%%a
      set L=%%b
      set ID=!F!!L:~0,1!
      Echo Creating user !ID!
      DSAdd User "CN="%%a" "%%b",%OUDomain%" -SAMID "!ID!" -UPN "!ID!" -FN "%%a" -LN "%%b" -Display "%%a %%b" -Desc "%%c" -Tel "%%d" -Office "%%e SeatNo: %%f" -Dept "%%g" -Email "%%h" -Company "%%i" -pwd %%j -Disabled No -PwdNeverExpires Yes >>C:\NewAccReport.txt
)      

Goto End
:ShowErr
Echo 'C:\Accounts.txt' File not found.
:END
ENDLOCAL
:: Batch Script End

Author

Commented:
Everything looks fine.User logon name is displaying correctly as Sharathr but there is a drop down menu in which the domain name is specified.That does not select.
1.In the address menu we have State and county can we specify even these.
2.Can we add the user to a group called .NEw joiners.?


THX
Sharath
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
* You need to set state and country manualy.
* Before running following script set values of following variables.
SET OUDomain=OU=Accounts,DC=Training,DC=Com                              <- OU Membership      
SET GMember=CN=New Joiners,OU=Accounts,DC=Training,DC=Com   <- Group Membership
SET MailDomain=training.com                                                                   <- Drop down Domain name  
* Please specify ALL your requirements once :)

:: Batch Script Start
:: a) -FN      = First Name
:: b) -LN      = Last Name
:: c) -Desc    = EmpId
:: d) -Tel     = ExtNo
:: e) -Office  = Building
:: f) -Office  = SeatNo
:: g) -Dept    = Department Name
:: h) -Email   = E-Mail Address
:: i) -Company = Location
:: j) -pwd     = password

@Echo Off
SETLOCAL Enabledelayedexpansion
IF NOT EXIST C:\Accounts.txt Goto ShowErr

SET OUDomain=OU=Accounts,DC=Training,DC=Com
SET GMember=CN=New Joiners,OU=Accounts,DC=Training,DC=Com
SET MailDomain=training.com

FOR /F "delims=, tokens=1-10" %%a IN (C:\Accounts.txt) Do (
      set F=%%a
      set L=%%b
      set ID=!F!!L:~0,1!
      Echo Creating user !ID!
      DSAdd User "CN="%%a" "%%b",%OUDomain%" -SAMID "!ID!" -UPN "!ID!@%MailDomain%" -FN "%%a" -LN "%%b" -Display "%%a %%b" -Desc "%%c" -Tel "%%d" -Office "%%e SeatNo: %%f" -Dept "%%g" -Email "%%h" -Company "%%i" -pwd %%j -Disabled No -PwdNeverExpires Yes -MemberOf "%GMember%" >>C:\NewAccReport.txt
)      

Goto End
:ShowErr
Echo 'C:\Accounts.txt' File not found.
:END
ENDLOCAL
:: Batch Script End

Author

Commented:
I get this

Creating user Maheshm
dsadd failed:CN=Mahesh mahesh,OU=Named Accounts,OU=User Accounts,OU=IND,OU=Count
ries,DC=Development,DC=xxxGroup,DC=co,DC=uk:The specified user does not exist.
:The object was created successfully but there was an error during post create o
perations.
type dsadd /? for help.Press any key to continue . . .
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Can you plz show what you have inside C:\Accounts.txt file? and what value you have set for OUDomain, GMember, MailDomain variables?

Author

Commented:
Accounts file.

Mahesh,mahesh,1809,9840190004,House,no28,HR,sindhur@iplc.com,Perungudi,abc123

Script

@Echo Off
SETLOCAL Enabledelayedexpansion
IF NOT EXIST C:\Accounts.txt Goto ShowErr

SET OUDomain=OU=Named Accounts,OU=User Accounts,OU=IND,OU=Countries,DC=Development,DC=Group,DC=co,DC=uk
SET GMember=CN=Chennai_NewJoiners,OU=Chennai Distribution Groups,DC=group,DC=Co,DC=uk
SET MailDomain=development.group.co.uk

FOR /F "delims=, tokens=1-10" %%a IN (C:\Accounts.txt) Do (
      set F=%%a
      set L=%%b
      set ID=!F!!L:~0,1!
      Echo Creating user !ID!
      DSAdd User "CN="%%a" "%%b",%OUDomain%" -SAMID "!ID!" -UPN "!ID!@%MailDomain%" -FN "%%a" -LN "%%b" -Display "%%a %%b" -Desc "%%c" -Tel "%%d" -Office "%%e SeatNo: %%f" -Dept "%%g" -Email "%%h" -Company "%%i" -pwd %%j -Disabled No -PwdNeverExpires Yes -MemberOf "%GMember%" >>C:\NewAccReport.txt
)      

Goto End
:ShowErr
Echo 'C:\Accounts.txt' File not found.
:END
ENDLOCAL
:: Batch Script End
Pause

Author

Commented:
I just checked the user mahesh is created but the Newaccreport.txt is not being updated and Password never expires.This user is not added to the member group.
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
It works perfectly at my end, assign group membership, checks password never expires and also updates the report.
Varify following group membership I think something wrong with OU name, group name or domain name.:
SET GMember=CN=Chennai_NewJoiners,OU=Chennai Distribution Groups,DC=group,DC=Co,DC=uk

Author

Commented:
This group Chennai Distribution Groups is not in my domain but in a different domain the root domain

SET GMember=CN=Chennai_NewJoiners,OU=Chennai Distribution Groups,DC=group,DC=Co,DC=uk

Is it possible up update the user eventhough a entry is not mentioned correctly in account.txt
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
No,  not possible, also change Chennai Distribution Groups with the group that exists on the same domain.

Author

Commented:
I am using this script.

@Echo Off
SETLOCAL Enabledelayedexpansion
IF NOT EXIST C:\Accounts.txt Goto ShowErr

SET OUDomain=OU=Named Accounts,OU=User Accounts,OU=IND,OU=Countries,DC=Development,DC=Group,DC=co,DC=uk
SET GMember=CN=Chennai_NewJoiners,OU=Chennai Distribution Groups,DC=group,DC=Co,DC=uk
SET MailDomain=development.group.co.uk

FOR /F "delims=, tokens=1-10" %%a IN (C:\Accounts.txt) Do (
      set F=%%a
      set L=%%b
      set ID=!F!!L:~0,1!
      Echo Creating user !ID!
      DSAdd User "CN="%%a" "%%b",%OUDomain%" -SAMID "!ID!" -UPN "!ID!@%MailDomain%" -FN "%%a" -LN "%%b" -Display "%%a %%b" -Desc "%%c" -Tel "%%d" -Office "%%e SeatNo: %%f" -Dept "%%g" -Email "%%h" -Company "%%i" -pwd %%j -Disabled No -PwdNeverExpires Yes -MemberOf "%GMember%" >>C:\NewAccReport.txt
)      

Goto End
:ShowErr
Echo 'C:\Accounts.txt' File not found.
:END
ENDLOCAL
:: Batch Script End
Pause

Is there any thing i need to change password never expires and the txt report does not get updated

Author

Commented:
The user is getting created but it give this message.

Creating user YuvrajR
dsadd failed:CN=Yuvraj Reddy,OU=Named Accounts,OU=User Accounts,OU=IND,OU=Countr
ies,DC=Development,DC=xxxGroup,DC=co,DC=uk:The specified user does not exist.:
The object was created successfully but there was an error during post create op
erations.
type dsadd /? for help.Press any key to continue . . .
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Check 'GMember' variables value and set it with a group name on the same domain and correct OU.
Above script will work perfectly if you give correct inputs inside Accounts.txt and define correct values of variables inside the script.
This script fulfils all your requirements; it selects passwords never expires and updates the report.

Author

Commented:
Why am i getting this.

Creating user YuvrajR
dsadd failed:CN=Yuvraj Reddy,OU=Named Accounts,OU=User Accounts,OU=IND,OU=Countr
ies,DC=Development,DC=Group,DC=co,DC=uk:The specified user does not exist.:
The object was created successfully but there was an error during post create op
erations.
type dsadd /? for help.Press any key to continue . . .
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Show me the values you have set for variables inside the script.

Author

Commented:
In the script file
@Echo Off
SETLOCAL Enabledelayedexpansion
IF NOT EXIST C:\Accounts.txt Goto ShowErr

SET OUDomain=OU=Named Accounts,OU=User Accounts,OU=IND,OU=Countries,DC=Development,DC=xxxGroup,DC=co,DC=uk
SET GMember=CN=Chennai_NewJoiners,OU=Chennai Distribution Groups,DC=xxxgroup,DC=Co,DC=uk
SET MailDomain=development.xxxgroup.co.uk

FOR /F "delims=, tokens=1-10" %%a IN (C:\Accounts.txt) Do (
      set F=%%a
      set L=%%b
      set ID=!F!!L:~0,1!
      Echo Creating user !ID!
      DSAdd User "CN="%%a" "%%b",%OUDomain%" -SAMID "!ID!" -UPN "!ID!@%MailDomain%" -FN "%%a" -LN "%%b" -Display "%%a %%b" -Desc "%%c" -Tel "%%d" -Office "%%e SeatNo: %%f" -Dept "%%g" -Email "%%h" -Company "%%i" -pwd %%j -Disabled No -PwdNeverExpires Yes -MemberOf "%GMember%" >>C:\NewAccReport.txt
)      

Goto End
:ShowErr
Echo 'C:\Accounts.txt' File not found.
:END
ENDLOCAL
:: Batch Script End
Pause

Systems Engineer
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
DSQuery group -name Chennai_NewJoiners*
  > No results
DSQuery group -name Chennai*
> No results

When i run this script also i get no errors.
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
That means Chennai_NewJoiners is an invalid group name or it does not exists on the same domain.
What about password never expire and report?

Author

Commented:
Thanks a lot for the patient support you have provided great job.Thanks....
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.