The procedure detailed was inspired by a knowledge base article at Microsoft
http://support.microsoft.com/support/kb/articles/Q180/4/64.ASP
I have successfully added over 3000 NT domain user accounts and created home
directories with correct permissions using this method. All files mentioned
here should be in the same subdirectory on a PDC or BDC. I keep mine in
C:\BIN on my IMail machine that is installed on a BDC. You should be able to
cut and paste each section, naming the file as appropriate. Edit to
customize for your configuration.
I use a semicolon delimited text file containing the users to be added
(EMAILADD.DAT) and another containing users to be deleted (EMAILDEL.DAT).
The format is as follows:
EMAILADD.DAT (contains users to add; description of each field is contained
in ADDNEW.CMD)
----------------------------------------------------------------------------
---------------------
jsmith;"John Q.
Smith";password1;"Student";H:;\\computer\users\jsmith;*;students.bat;John;Q;
Smith;@
tjones;"Tom R.
Jones";password2;"Student";H:;\\computer\users\tjones;*;students.bat;Tom;R;J
ones;@
----------------------------------------------------------------------------
---------------------
EMAILDEL.DAT (Same format as above, contains users to delete)
----------------------------------------------------------------------------
---------------------
jsmith;"John Q.
Smith";password1;"Student";H:;\\computer\users\jsmith;*;students.bat;John;Q;
Smith;@
tjones;"Tom R.
Jones";password2;"Student";H:;\\computer\users\tjones;*;students.bat;Tom;R;J
ones;@
----------------------------------------------------------------------------
---------------------
I run MAKENEW.BAT to add the users in EMAILADD.DAT which calls ADDNEW.CMD
MAKENEW.BAT
----------------------------------------------------------------------------
---------------------
@echo off
C:
CD C:\BIN
@echo *** The new users are being added. ***
addnew.cmd
----------------------------------------------------------------------------
---------------------
Line by line ADDNEW.CMD (heavily commented) reads EMAILADD.DAT and passes
each field as parameters to ADDNEW2.CMD
ADDNEW.CMD
----------------------------------------------------------------------------
---------------------
REM You can delete/REM the following line for troubleshooting.
REM @echo off
REM Parse emailadd.dat and pass each field as a variable to addnew2.cmd
FOR /F "delims=; tokens=1,2,3,4,5,6,7,8,9,10,11" %%a in (emailadd.dat) do
call addnew2.cmd %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k
echo ---------
echo - Finished.
echo ---------
:End
REM Variables are passed as follows:
REM Token 1 is Username passed as %%a, addnew2.cmd sees it as %1
REM Token 2 is Fullname passed as %%b, addnew2.cmd sees it as %2; needs
quotes
REM Token 3 is Password passed as %%c, addnew2.cmd sees it as %3
REM Token 4 is Description passed as %%d, addnew2.cmd sees it as %4; needs
quotes
REM Token 5 is ? passed as %%e, addnew2.cmd sees it as %5
REM Token 6 is Home directory passed as %%f, addnew2.cmd sees it as %6
REM Token 7 is Profile passed as %%g, addnew2.cmd sees it as %7
REM Token 8 is Script passed as %%h, addnew2.cmd sees it as %8
REM Token 9 is First Name passed as %%i, addnew2.cmd sees it as %9
REM Token 10 is Middle Name passed as %%j, addnew2.cmd sees it as %10
REM Token 11 is Last Name as %%k, addnew2.cmd sees it as %11
REM Brief description of the usage of tokens in the FOR command
REM FOR /F ["options"] %variable IN (filenameset) DO command
[command-parameters]
REM
REM filenameset is one or more file names. Each file is opened, read
REM and processed before going on to the next file in filenameset.
REM Processing consists of reading in the file, breaking it up into
REM individual lines of text and then parsing each line into zero or
REM more tokens. The body of the for loop is then called with the
REM variable value(s) set to the found token string(s). By default, /F
REM passes the first blank separated token from each line of each file.
REM Blank lines are skipped. You can override the default parsing
REM behavior by specifying the optional "options" parameter. This
REM is a quoted string which contains one or more keywords to specify
REM different parsing parameters. The keywords are:
REM
REM eol=c - specifies an end of line comment character
REM (just one)
REM skip=n - specifies the number of lines to skip at the
REM beginning of the file.
REM delims=xxx - specifies a delimeter set. This replaces the
REM default delimiter set of space and tab.
REM tokens=x,y,m-n - specifies which tokens from each line are to
REM be passed to the for body for each iteration.
REM This will cause additional variable names to
REM be allocated. The m-n form is a range,
REM specifying the mth through the nth tokens. If
REM the last character in the tokens= string is an
REM asterisk, then an additional variable is
REM allocated and receives the remaining text on
REM the line after the last token parsed.
REM
REM Some examples might help:
REM
REM FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i
%j %k
REM
REM would parse each line in myfile.txt, ignoring lines that begin with
REM a semicolon, passing the 2nd and 3rd token from each line to the for
REM body, with tokens delimited by commas and/or spaces. Notice the for
REM body statements reference %i to get the 2nd token, %j to get the
REM 3rd token, and %k to get all remaining tokens after the 3rd.
REM
REM %i is explicitly declared in the for statement and the %j and %k
REM are implicitly declared via the tokens= option. You can specify up
REM to 26 tokens via the tokens= line, provided it does not cause an
REM attempt to declare a variable higher than the letter 'z'. Remember,
REM FOR variable names are global, and you can't have more than 26 total
REM active at any one time.
REM
REM For additional help type "HELP FOR" at the NT command prompt
----------------------------------------------------------------------------
---------------------
ADDNEW2.CMD takes the parameters passed to it and uses them to perform
various user functions using basic NT command line utilities such as NET,
CACLS and MKDIR. Here I create the user account, add it to a localgroup,
make the users home directory, assign permissions to the home directory, add
the user to a list and create an email alias. Note: since you can only use
%0-%9 as variables, I used the DOS command SHIFT to gain access to fields
%10 and %11.
ADDNEW2.CMD
----------------------------------------------------------------------------
---------------------
ECHO Creating Account for %2
NET USER %1 %3 /ADD /FULLNAME:%2 /COMMENT:%4 /HOMEDIR:%6 /SCRIPTPATH:%8
NET LOCALGROUP "email" %1 /ADD
SET USERNAME=%1
MKDIR \\COMPUTER\E$\USERS\%1
cacls \\COMPUTER\E$\USERS\%1 /T /G Administrators:F %1:F < yes.txt
echo [EMAIL PROTECTED]>>d:\imail\lists\students\users.txt
echo [EMAIL PROTECTED]>>d:\imail\lists\students\users.lst
SHIFT
SHIFT
d:\imail\addalias -a %7.%8.%9=%USERNAME%
:End
----------------------------------------------------------------------------
---------------------
To remove the users in EMAILDEL.DAT I run a batch file that simply calls
REMUSER.CMD
DELOLD.BAT
----------------------------------------------------------------------------
---------------------
@echo off
C:
CD C:\BIN
@echo *** The existing users are being deleted. ***
remuser.cmd
----------------------------------------------------------------------------
---------------------
Line by line REMUSER.CMD (heavily commented) reads EMAILDEL.DAT and passes
each field as parameters to REMUSER2.CMD
REMUSER.CMD
----------------------------------------------------------------------------
---------------------
REM You can delete/REM the following line for troubleshooting.
REM @echo off
REM Parse emaildel.dat and pass each field as a variable to remuser2.cmd
FOR /F "tokens=1,2,3,4,5,6,7,8,9,10,11 delims=;" %%a in (emaildel.dat) do
call REMUSER2 %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k
echo ---------
echo - Finished.
echo ---------
:End
REM Variables are passed as follows:
REM Token 1 is Username passed as %%a, remuser2.cmd sees it as %1
REM Token 2 is Fullname passed as %%b, remuser2.cmd sees it as %2; needs
quotes
REM Token 3 is Password passed as %%c, remuser2.cmd sees it as %3
REM Token 4 is Description passed as %%d, remuser2.cmd sees it as %4; needs
quotes
REM Token 5 is ? passed as %%e, remuser2.cmd sees it as %5
REM Token 6 is Home directory passed as %%f, remuser2.cmd sees it as %6
REM Token 7 is Profile passed as %%g, remuser2.cmd sees it as %7
REM Token 8 is Script passed as %%h, remuser2.cmd sees it as %8
REM Token 9 is First Name passed as %%i, remuser2.cmd sees it as %9
REM Token 10 is Middle Name passed as %%j, remuser2.cmd sees it as %10
REM Token 11 is Last Name as %%k, remuser2.cmd sees it as %11
REM Brief description of the usage of tokens in the FOR command
REM FOR /F ["options"] %variable IN (filenameset) DO command
[command-parameters]
REM
REM filenameset is one or more file names. Each file is opened, read
REM and processed before going on to the next file in filenameset.
REM Processing consists of reading in the file, breaking it up into
REM individual lines of text and then parsing each line into zero or
REM more tokens. The body of the for loop is then called with the
REM variable value(s) set to the found token string(s). By default, /F
REM passes the first blank separated token from each line of each file.
REM Blank lines are skipped. You can override the default parsing
REM behavior by specifying the optional "options" parameter. This
REM is a quoted string which contains one or more keywords to specify
REM different parsing parameters. The keywords are:
REM
REM eol=c - specifies an end of line comment character
REM (just one)
REM skip=n - specifies the number of lines to skip at the
REM beginning of the file.
REM delims=xxx - specifies a delimeter set. This replaces the
REM default delimiter set of space and tab.
REM tokens=x,y,m-n - specifies which tokens from each line are to
REM be passed to the for body for each iteration.
REM This will cause additional variable names to
REM be allocated. The m-n form is a range,
REM specifying the mth through the nth tokens. If
REM the last character in the tokens= string is an
REM asterisk, then an additional variable is
REM allocated and receives the remaining text on
REM the line after the last token parsed.
REM
REM Some examples might help:
REM
REM FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i
%j %k
REM
REM would parse each line in myfile.txt, ignoring lines that begin with
REM a semicolon, passing the 2nd and 3rd token from each line to the for
REM body, with tokens delimited by commas and/or spaces. Notice the for
REM body statements reference %i to get the 2nd token, %j to get the
REM 3rd token, and %k to get all remaining tokens after the 3rd.
REM
REM %i is explicitly declared in the for statement and the %j and %k
REM are implicitly declared via the tokens= option. You can specify up
REM to 26 tokens via the tokens= line, provided it does not cause an
REM attempt to declare a variable higher than the letter 'z'. Remember,
REM FOR variable names are global, and you can't have more than 26 total
REM active at any one time.
REM
REM For additional help type "HELP FOR" at the NT command p
----------------------------------------------------------------------------
---------------------
REMUSER2.CMD takes the parameters passed to it and uses them to perform
various user functions using basic NT command line utilities such as NET and
RMDIR. Here I delete the user account, delete the users home directory and
remove the users mail directory. Note: I need to include a command to remove
the users alias.
REMUSER2.CMD
----------------------------------------------------------------------------
---------------------
ECHO Deleting Account for %2
NET USER %1 /DELETE /DOMAIN
REM
ECHO Y | RMDIR /S \\COMPUTER\E$\USERS\%1
ECHO Y | RMDIR /S \\computerl\d$\imail\users\%1
:End
----------------------------------------------------------------------------
---------------------
YES.TXT must be created in a special way. Cut and paste will not work here.
YES.TXT
Open a Command Prompt (Cmd.exe) and change directories to the directory
where the above files are kept.
Type the following:
COPY CON YES.TXT <press the enter key>
y<press the enter key>
<Press Control-Z to exit and save the file>
This will create a text file with the Y and ENTER needed to automate the
CACLS command.
> -----Original Message-----
> From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, December 30, 1999 2:11 AM
> To: [EMAIL PROTECTED]
> Subject: [IMail Forum] OT - Automating adding users and domains on NT
>
> We are a hosting firm that is growing. Up to now we have been manually
> creating NT users, creating DNS entries, adding the web/ftp site to IIS 4,
> setting up Web Trends, and of course creating Imail domains and users.
> Imail seems to be the easiest to automate. How are other NT admins
> streamlining these other processes? What NT tools are you using?
>
> Thanks for any insight you may have,
> Don
>
>
>
> Please visit http://www.ipswitch.com/support/mailing-lists.html
> to be removed from this list.
Please visit http://www.ipswitch.com/support/mailing-lists.html
to be removed from this list.