Friday, July 1, 2011

Create Users for Testing Purposes


Method 2: By using the DSADD USER command:

dsadd user "cn=Test User,ou=Test OU,dc=india,dc=net" -samid 
testuser -upn testuser@india.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 create the "Test OU" OU in you AD, and also change the DN of the domain to the name of YOUR domain.
However we would like to create many users for testing purposes. Therefore we can use the FOR command like we did before:
FOR /L %i in (1,1,500) DO dsadd user "cn=Test User%i,ou=Test 
OU,dc=india,dc=net" -samid testuser%i -upn testuser%i@india.net
-fn Test -ln User%i -display "Test 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:
Blue,Kelly,bluek,04-6545645
Ben-Sachar,Ido,bensachari,03-7634545
Fluegel,Jay,fluegelj,03-9875765
Grande,Jon,grandej,02-6674534
Hankin,Alex,hankina,04-8856476
Name the file USERS.TXT and place it in a directory.
Now open a CMD in that directory and run the following command:
for /F "eol=; tokens=1,2,* delims=," %%i in (users.txt) do 
dsadd user "cn=%%j %%i,ou=Test OU,dc=india,dc=net" -samid 
%%k -upn %%k@india.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!

Create Users for Testing Purposes


Method 1: By using the NET USER command:

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:

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:

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 script will create local users. If run on a DC it will create users in the USERS Container 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 command above. However, if you want, from that computer, to create users in the Active Directory database on the DC, use this command instead:

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 company's usernames or a database with usernames) create a text file like this one:

daniel
moshe
yossy
gabi
ran
Name the file USERS.TXT and place it in a directory.
Now open a CMD in that directory and run the following command:

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 with the same password - P@ssw0rd. You don't have to use the /domain switch unless you want to.

Change Recovery Console Password

On Windows Server 2003, the setpwd or NET USER trick won't work. Here, if you want to change the Directory Service Restore Mode Administrator password you'll need to use the following method:
1.                  Click, Start, click Run, type
ntdsutil
and then click OK.
  1. At the Ntdsutil command prompt, type
set dsrm password
  1. At the DSRM command prompt, type one of the following lines:
To reset the password on the server on which you are working, type
reset password on server null
The null variable assumes that the DSRM password is being reset on the local computer. Type the new password when you are prompted. Note that no characters appear while you type the password.
or
To reset the password for another server, type
reset password on server
where is the DNS name for the server on which you are resetting the DSRM password. Type the new password when you are prompted. Note that no characters appear while you type the password.
  1. At the DSRM command prompt, type q.
  2. At the Ntdsutil command prompt, type q to exit.
You can now use the Administrator account to log on to Recovery Console or Directory Services Restore Mode using the new password.