Vous êtes sur la page 1sur 7

http://serverfault.

com/questions/209549/how-can-i-quickly-create-100-users-on-my
-active-directory-for-testing-purposes
http://www.testools.net/2013/01/how-to-create-several-users-in-active.html
https://www.petri.com/create_users_for_testing_purposes#1
If you want to create a large amount of test user accounts in your domain or loc
al accounts on your workstation, you can do so in more than one way. On this pag
e I ll try to list a few of these methods.
By
By
By
By

using
using
using
using

the
the
the
the

NET USER command


DSADD USER command
CSVDE command
LDIFDE command

If you happen to have some nice scripts that can do the same job in other method
s (oh yes, there are other methods), please do send me an e-mail and I ll upload i
t to this page .
Windows Server 2003 AD Note: Windows Server 2003 Active Directory is configured,
by default, to request that any user that you create will have a password that
is complex and with a minimum of 7 characters. Some methods described here (main
ly method #3 and #4) cannot add the password attribute to a user account. In ord
er for these methods to work in your test environment you must first disable the
password requirement for the Windows Server 2003-based Domain. Read my Disable
Password Requirements in Windows Server 2003 Domains article for more info.
Method #1: By using the NET USER command
NET USER is an old NT-related user manipulation command. I will not list all of
it s attributes here (you can find for yourself by going to the Help and Support s
ite on your computer). I do not usually use the NET USER command in an AD enviro
nment, mostly due to the fact that it is not tailored for AD objects at all, but
still, it can be used for our needs.
You can use the FOR and NET USER commands to accomplish the task in a quick and d
irty way, without scripting or writing any code. For example, if you type from th
e command prompt:
1. FOR /L %i in (1,1,500) DO NET USER MyUser%i /ADD
This will result in creating 500 new users, named MyUser1, MyUser2, etc. You can
, of course, customize the FOR command s parameters. See the FOR command help for
more options.
You can also set the user s password (in this case

P@ssw0rd) in the same manner:

1 FOR /L %i in (1,1,500) DO NET USER MyUser%i P@ssw0rd /ADD


You can delete all those users by running the following command:
1 FOR /L %i in (1,1,500) DO NET USER MyUser%i /DELETE
Note: If run on a stand alone W2K Server, W2K PRO or on an XP machine, this scri
pt will create local users. If run on a DC it will create users in the USERS Con
tainer in the AD. However, doing so on a domain controller will not create fully
AD-compatible users (as you can clearly see if you open one of these users and
try to find the User Principal Name
UPN
field).

Note: If you re using a W2K PRO or XP PRO computer that is connected to an Active
Directory network and you wish to create local users on that computer
run the co
mmand above. However, if you want, from that computer, to create users in the Ac
tive Directory database on the DC, use this command instead:
1 FOR /L %i in (1,1,500) DO NET USER MyUser%i P@ssw0rd /domain /ADD
To create users with pre-configured names (for example a file with all your comp
any s usernames or a database with usernames) create a text file like this one:
1
2
3
4
5
6
7
8

daniel
moshe
yossy
gabi
ran
bijo
baruch
bibi

Name the file USERS.TXT and place it in a directory.


Now open a CMD in that directory and run the following command:
1. FOR /F %i in (users.txt) DO NET USER %i P@ssw0rd /domain /ADD
This will create user accounts with the names found in the USERS.TXT file, all w
ith the same password
P@ssw0rd. You don t have to use the /domain switch unless yo
u want to.
See the NET USER or NET USERS command help for more options.
Method #2: By using the DSADD USER command
DSADD USER is a command found in Windows Server 2003, and is specifically tailor
ed for AD usage. Almost any user-related attribute can be set by using this comm
and.
Note: The DSADD command is not just about adding users. Run DSADD /? in your CMD
window and see for yourself.
For example, if you type from the command prompt:
1 dsadd user "cn=Test User,ou=Test OU,dc=dpetri,dc=net" -samid testuser -upn tes
tuser@dpetri.net -fn Test -ln User -display "Test User" -pwd P@ssw0rd -disabled
no
This will create one user called Test User with all the necessary information (and
as I said earlier, more attributes can be easily configured in the same way).
Lamer Note: Note that you want to use the same syntax as above, you must first c
reate the Test OU OU in you AD, and also change the DN of the domain to the name o
f YOUR domain.
However we would like to create many users for testing purposes. Therefore we ca
n use the FOR command like we did before:
1 FOR /L %i in (1,1,500) DO dsadd user "cn=Test User%i,ou=Test OU,dc=dpetri,dc=n
et" -samid testuser%i -upn testuser%i@dpetri.net -fn Test -ln User%i -display "T
est User%i" -pwd P@ssw0rd -disabled no
This script will create 500 users called Test User1, Test User2 and so on.

Like with NET USER, the DSADD USER command can be used along with a text or CSV
file that contains a list of all the users that you want to build.
Create a text file like this one:

1 Blue,Kelly,bluek,04-6545645
2 Ben-Sachar,Ido,bensachari,03-7634545
3 Fluegel,Jay,fluegelj,03-9875765
4 Grande,Jon,grandej,02-6674534
5 Hankin,Alex,hankina,04-8856476
6 Jiang,George,jiangg,08-7636344
7 Kelly,Robert,kellyr,03-5568336
8 Kelly,Bob,kellyb,03-9567474
9 Li,Yuhong,liy,02-5462272
10 Moreland,Barbara,morelandb,04-88293922
11 Naik,Mandar,naikm,03-5531190
12 O'Donnell,Claire,odonnellc,03-5111930
13 Smith,John,smithj,03-8102201
Name the file USERS.TXT and place it in a directory.
Now open a CMD in that directory and run the following command:
1 for /F "eol=; tokens=1,2,* delims=," %%i in (users.txt) do dsadd user "cn=%%j
%%i,ou=Test OU,dc=dpetri,dc=net" -samid %%k -upn %%k@dpetri.net -fn %%j -ln %%i
-display "%%j %%i" -pwd P@ssw0rd -disabled yes
This will create user accounts with the names found in the USERS.TXT file.
Imagine the power of such a script!
Method #3: By using the CSVDE command
CSVDE is a command that can be used to import and export objects to and from the
AD into a CSV-formatted file. A CSV (Comma Separated Value) file is a file easi
ly readable in Excel.
I will not go to length into this powerful command, but I will show you some bas
ic samples of how to import a large number of users into your AD. Of course, as
with the DSADD command, CSVDE can do more than just import users. Consult your h
elp file for more info.
For example, lets say I would like to create a number of very simple users. Just
the necessary information, nothing more.
Create a text file like this one:
1 dn,sAMAccountName,userPrincipalName,userAccountControl,objectClass
2 "CN=Amie Baldwin,OU=Test OU,DC=dpetri,DC=net",amieb,amieb@dpetri.net,512,user
3 "CN=Scott Culp,OU=Test OU,DC=dpetri,DC=net",scottc,scottc@dpetri.net,512,user
4 "CN=Derek Graham,OU=Test OU,DC=dpetri,DC=net",derekg,derekg@dpetri.net,512,use
r
5 "CN=Stephanie Bourne,OU=Test OU,DC=dpetri,DC=net",stephanieb,stephanieb@dpetri
.net,512,user
6 "CN=Matthew Dunn,OU=Test OU,DC=dpetri,DC=net",matthewd,matthewd@dpetri.net,512
,user

Name the file USERS.CSV and place it in a directory.


Open a CMD in that directory and run the following command:
1 csvde -i -f users.csv
(use your own path)
This will create 5 user accounts with the names found in the USERS.CSV file.
Note: Note that CSVDE, unlike DSADD USER, cannot import passwords into the AD. F
or that reason, unless you specify the userAccountControl attribute as 512, the
users that will be imported will be disabled by default. Also remember that you
must Disable Password Requirements in Windows Server 2003 Domains in order for t
his command to work in Windows Server 2003-based domains.
Now lets say I would like to create the same users but this time with associated
mailboxes stored on my Exchange server called SERVER100.
Create a text file like this one (select all and just copy):

1 DN,objectClass,name,homeMDB,cn,displayName,mail,givenName,proxyAddresses,sAMAc
countName,sn,userAccountControl,userPrincipalName,homeMTA,msExchHomeServerName,m
ailNickname,countryCode,c,l,homePhone,mobile,telephoneNumber,co,wWWHomePage
2 "CN=kuku levi,OU=Test OU,DC=dpetri,DC=net",user,kuku levi,"CN=Mailbox Store (S
ERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=
First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Excha
nge,CN=Services,CN=Configuration,DC=dpetri,DC=net",kuku levi,kuku levi,kukul@dpe
tri.net,kuku,SMTP:kukul@dpetri.net;X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi'
;g=kuku';,kukul,levi,512,kukul@dpetri.net,"CN=Microsoft MTA,CN=SERVER100,CN=Serv
ers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsof
t Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Adm
inistrative Group/cn=Configuration/cn=Servers/cn=SERVER100,kukul,376,IL,Tel-Aviv
,03-4534545,051-345345,03-4534545,ISRAEL,www.petri.com
3 "CN=momo levi,OU=Test OU,DC=dpetri,DC=net",user,momo levi,"CN=Mailbox Store (S
ERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=
First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Excha
nge,CN=Services,CN=Configuration,DC=dpetri,DC=net",momo levi,momo levi,momol@dpe
tri.net,momo,SMTP:momol@dpetri.net;X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi'
;g=momo';,momol,levi,512,momol@dpetri.net,"CN=Microsoft MTA,CN=SERVER100,CN=Serv
ers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsof
t Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Adm
inistrative Group/cn=Configuration/cn=Servers/cn=SERVER100,momol,376,IL,Tel-Aviv
,03-9879878,053-878345,03-9879878,ISRAEL,www.msn.co.il
4 "CN=jojo levi,OU=Test OU,DC=dpetri,DC=net",user,jojo levi,"CN=Mailbox Store (S
ERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=
First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Excha
nge,CN=Services,CN=Configuration,DC=dpetri,DC=net",jojo levi,jojo levi,jojol@dpe
tri.net,jojo,SMTP:jojol@dpetri.net;X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi'
;g=jojo';,jojol,levi,512,jojol@dpetri.net,"CN=Microsoft MTA,CN=SERVER100,CN=Serv
ers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsof
t Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Adm
inistrative Group/cn=Configuration/cn=Servers/cn=SERVER100,jojol,376,IL,Tel-Aviv
,03-2424478,053-654654,03-2424878,ISRAEL,www.cnn.com

5 "CN=bubu levi,OU=Test OU,DC=dpetri,DC=net",user,bubu levi,"CN=Mailbox Store (S


ERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=
First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Excha
nge,CN=Services,CN=Configuration,DC=dpetri,DC=net",bubu levi,bubu levi,bubul@dpe
tri.net,bubu,SMTP:bubul@dpetri.net;X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi'
;g=bubu';,bubul,levi,512,bubul@dpetri.net,"CN=Microsoft MTA,CN=SERVER100,CN=Serv
ers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsof
t Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Adm
inistrative Group/cn=Configuration/cn=Servers/cn=SERVER100,bubul,376,IL,Tel-Aviv
,03-8768767,053-456658,03-8768767,ISRAEL,www.cnn.com
6 "CN=dudu levi,OU=Test OU,DC=dpetri,DC=net",user,dudu levi,"CN=Mailbox Store (S
ERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=
First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Excha
nge,CN=Services,CN=Configuration,DC=dpetri,DC=net",dudu levi,dudu levi,dudul@dpe
tri.net,dudu,SMTP:dudul@dpetri.net;X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi'
;g=dudu';,dudul,levi,512,dudul@dpetri.net,"CN=Microsoft MTA,CN=SERVER100,CN=Serv
ers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsof
t Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Adm
inistrative Group/cn=Configuration/cn=Servers/cn=SERVER100,dudul,376,IL,Tel-Aviv
,03-5645446,051-978879,03-5645446,ISRAEL,www.disney.com
Note: The text might look a bit garbled, but if you copy and paste inside a new
text file you ll see it fine. Excel will also help you with editing the file.
Sponsored
Lamer Note: This might be a good point to remind you to USE YOUR OWN NAMES!!!
Name the file USERS.CSV and place it in a directory.
Open a CMD in that directory and run the following command:
1 csvde -i -f users.csv
(use your own path)
This will create 5 user accounts with the names found in the USERS.CSV file, alo
ngside with some nice attributes for each user.
Method #4: By using the LDIFDE command
Like CSVDE, LDIFDE is a command that can be used to import and export objects to
and from the AD into a LDIF-formatted file. A LDIF (LDAP Data Interchange Forma
t) file is a file easily readable in any text editor, however it is not readable
in programs like Excel. The major difference between CSVDE and LDIFDE (besides
the file format) is the fact that LDIFDE can be used to edit and delete existing
AD objects (not just users), while CSVDE can only import and export objects.
Sponsored
Like in CSVDE, I will not go to length into this powerful command, but I will sh
ow you some basic samples of how to import a large number of users into your AD.
Of course, as with the DSADD command, LDIFDE can do more than just import users
. Consult your help file for more info. Here too, remember to Disable Password R
equirements in Windows Server 2003 Domains in order for this command to work in
Windows Server 2003-based domains.

For example, just like with the CSVDE command, lets say I would like to create a
number of very simple users. Just the necessary information, nothing more.
Create a text file like this one:
dn: CN=Amie Baldwin,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Amie Baldwin
objectClass: user
name: Amie Baldwin
sAMAccountName: amieb
telephoneNumber: 555-1234
userAccountControl: 514
userPrincipalName: amieb@dpetri.net
dn: CN=Scott Culp,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Scott Culp
department: Accounting
objectClass: user
name: Scott Culp
sAMAccountName: scottc
telephoneNumber: 555-1236
userAccountControl: 512
userPrincipalName: scottc@dpetri.net
dn: CN=Derek Graham,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Derek Graham
department: Accounting
objectClass: user
name: Derek Graham
sAMAccountName: derekg
telephoneNumber: 555-1239
userAccountControl: 512
userPrincipalName: derekg@dpetri.net
dn: CN=Stephanie Bourne,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Stephanie Bourne
department: Accounting
objectClass: user
name: Stephanie Bourne
sAMAccountName: stephanieb
telephoneNumber: 555-1239
userAccountControl: 512
userPrincipalName: stephanieb@dpetri.net
dn: CN=Matthew Dunn,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Matthew Dunn
department: Accounting
objectClass: user
name: Matthew Dunn
sAMAccountName: matthewd
telephoneNumber: 555-1230
userAccountControl: 512
userPrincipalName: matthewd@dpetri.net
Note that unlike the CSV-formatted file, the LDIF file is quite easy to understa

nd and edit in Notepad. However, you may find it easier to edit a large number o
f users via Excel than through Notepad, that s why the CSV-formatted file will sti
ll be easier to manipulate than the LDIF-formatted file.
Name the file USERS.LDF and place it in a directory.
Open a CMD in that directory and run the following command:
ldifde -i -f users.ldf
1
ldifde -i -f users.ldf
(use your own path)
This will create 5 user accounts with the names found in the USERS.LDF file.
Since the only difference between the CSVDE and LDIFDE commands is the file form
at I will stop here. Remember that you can add almost any user-configurable attr
ibute by using these commands. Test them on your own, and if you come up with a
truly amazing result please share it with us .
Links
Step-by-Step Guide to Bulk Import and Export to Active Directory
http://www.microsoft.com/windows2000/techinfo/planning/activedirectory/bulksteps
.asp
Importing and exporting directory information
http://www.microsoft.com/windows2000/en/server/help/sag_ad_ldif_csv.htm
Using LDIFDE to Import and Export Directory Objects to Active Directory
237677
http://support.microsoft.com/?kbid=237677
How to Use Csvde.exe to Import Contacts into Active Directory 300409
http://support.microsoft.com/?kbid=300409

Vous aimerez peut-être aussi