How to write a script to create user accounts from a file?

FreshPrince

Diamond Member
Dec 6, 2001
8,361
1
0
Does anyone have experience creating a script that pulls user account information from a file and create them in either AD or local machine?

I found some scripts, but most of them do not pull information like email address or security group membership :(
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
what OS?

I built a netsh script to mass add reservations to a DHCP server. I used perl to build the actual script, because I could pull stuff from a csv in the perl script very easy.

I also had an ldif excel macro, so I could make mass users and then just inport the ldif file into active directory...that is assuming you are using windows.
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
I'll have to dig deep for it...are you looking for the ldif, or the perl script that reads from a file and makes a netsh batch file? I am pretty sure that you can add users via netsh. The ldif thing was a bit cheasy. I used it to add 60K user objects into AD with email address attributes.


do a netsh /? on your server, or google for netsh commands. You basicly send a line from the command prompt that goes like:

netsh <server context stuff><attribute stuff>

my dhcp was like netsh dhcp server 192.168.0.1 scope 192.168.0.0 reservation add <Mac><Reservation name><Reservation comments>.

I had a CSV file with MAC,NAM,COMMENTS.

here is the script, in original format. I just had it print to a web page, so that we could pull it up on the dhcp server and copy it to a text file.

Code:
#!/usr/bin/perl
#this is a subroutine to build the array
use warnings;
use strict;
print "Content-Type: text/plain\n\n";
print "rem batch file for creation of DHCP reservations\n";
	open ALTDB, "/home/nickw/hp.ssv" or die $!;
my $lineno = 1;
while (<ALTDB>) {
	print "rem adding $_";
	print "netsh ";
	print "dhcp ";
	print "server "; 
	print "scope 216.119.196.0 ";
	print "add reservedip ";
	print "$_";
	$lineno++;
}
 

lansalot

Senior member
Jan 25, 2005
298
0
0
Why are you giving a script to create DHCP reservations when he is asking for user accounts?

To OP: you can find plenty of script like this with google, just search for "create user account in active directory" - there are plenty. However:

"but most of them do not pull information like email address or security group membership"

Are you wanting to read out email addresses and group membership - or set them? Either way, google is your friend here.
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
I posted my script. I wasn't about to write the script for him. This gives him the syntax to modify the netsh command to add user data. The $_ line is the current line in a file. He modifies the script so that it uses context for users, and then creates a space delimited file, and has this script pull from that file.


I was giving an example of pulling from a delimited file and building a script. I wish I had time to write one for him, but I have to work for a living.