Batch User Creation in Win2K3

Wetling23

Senior member
Aug 18, 2001
496
0
0
Every week, I get an e-mail with a list of...let's say, 20ish new user accounts that need to be created. Instead of getting a list of names in an e-mail, I'd like to setup an CSV file that I can distribute to the various managers. The problem appears to be though, that I can't use the CSV file to assign the new users to a set of default groups. Is that correct? What about assigning a default password?

Thanks.
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
I use an ldif/CSV file to create, and then use dsmod in a script to change the username. I don't remember if dsmod is in the normal install, or if it's from the server resource kit.

dsmod user cn=$username,cn=users,dc=example,dc=com -pwd changeme

would change the user that is in the default users container, in the domain "example.com" to changeme. I just use perl to pull the stuff from the ldif file. What I like to do, is setup a csv file in a specific format, feed that to a perl scrip that spits out an ldif file to feed to ldifde and a .bat file to change the passwords. Then I just copy those to the DC and run ldifde and import, then run the batch file to set them up. It's been a while since I have done any mass imports, but I used a combination of Excel, perl, ldifde and batch files to create 80K users in AD for testing stuff.
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
I've looked, but haven't found much yet. The other issue is that my scripts are meant for generating HUGE amounts of users (think 10-100K). I think I have a working ldif file you could use as an example, and maybe the perl script to take a csv/space seperated file and generate an LDIF, but unless you know some perl, it's probably worthless.

Perl Script to create a huge number of users....

#!/usr/bin/perl
#Script to create LDIF for AD Import
use warnings;
use strict;

my $number = 10000;
my $dn = ",ou=test users,dc=bugnet,dc=com";
my $maildomain = "\@bugnet.com";
my $usernamebase = "applabs";
my $n = 1;
while ($n <= $number)
{
print "dn: cn=$usernamebase$n$dn\n";
print "changetype:Add\n";
print "cn: $usernamebase$n\n";
print "description: User $n for testing\n";
print "objectClass: User\nsAMAccountName: $usernamebase$n\n";
print "mail: $usernamebase$n$maildomain\n\n";
$n++;
}
$number = 20000;
$dn = ",ou=test users2,dc=bugnet,dc=com";
while ($n <= $number)
{
print "dn: cn=$usernamebase$n$dn\n";
print "changetype:Add\n";
print "cn: $usernamebase$n\n";
print "description: User $n for testing\n";
print "objectClass: User\nsAMAccountName: $usernamebase$n\n";
print "mail: $usernamebase$n$maildomain\n\n";
$n++;
}


that was redirected to the ldif file. I could also easily just open a file, parse it line by line and split up the information (either space, tab, comma, etc) and then change so it so it uses the file to generate them, rather then generic users. You can also add/remove attributes, this was the bare minimal required for my testing.