Тема: Массовое добавление пользователей в домен AD
Вот возникла идейка облегчить жизнь народу, есть учиников, эдак 800, все они могут логиниться на терминаты, которые в свою очередь подсоединены к домену. Ну и есть ответственные люди, который скорее всео наберут их в екселе (наивно пологаю...), ну очень неохото деллигировать кому попало права...
Заничит так, имеем текстовой файл с паролями логинами именами и сроком годности... примерно в таком виде
logins.txt
login1<tab>pass1<tab>name1<tab>lastname1<tab>expdata2007-11-1
login2 pass2 name2 lastname2 expdata2007-11-2
login3 pass3 name3 lastname3 expdata2007-11-3
login4 pass4 name4 lastname4 expdata2007-11-4
login5 pass5 name5 lastname5 expdata2007-11-5
login6 pass6 name6 lastname6 expdata2007-11-6
login7 pass7 name7 lastname7 expdata2007-11-7
login8 pass8 name8 lastname8 expdata2007-11-8
login9 pass9 name9 lastname9 expdata2007-11-9
login10 pass10 name10 lastname10 expdata2007-11-10
login11 pass11 name11 lastname11 expdata2007-11-11
login12 pass12 name12 lastname12 expdata2007-11-12
login13 pass13 name13 lastname13 expdata2007-11-13
login14 pass14 name14 lastname14 expdata2007-11-14
login15 pass15 name15 lastname15 expdata2007-11-15
login16 pass16 name16 lastname16 expdata2007-11-16
и имеем замечательную команду Net user (правдо как выяснилось она не умеет доавлять пользователей в какойто конкретный OU, тока в OU Users)
The syntax of this command is:
NET USER
[username [password | *] [options]] [/DOMAIN]
username {password | *} /ADD [options] [/DOMAIN]
username [/DELETE] [/DOMAIN]
NET USER creates and modifies user accounts on computers. When used
without switches, it lists the user accounts for the computer. The
user account information is stored in the user accounts database.
This command works only on servers.
username Is the name of the user account to add, delete, modify, or
view. The name of the user account can have as many as
20 characters.
password Assigns or changes a password for the user's account.
A password must satisfy the minimum length set with the
/MINPWLEN option of the NET ACCOUNTS command. It can have as
many as 14 characters.
* Produces a prompt for the password. The password is not
displayed when you type it at a password prompt.
/DOMAIN Performs the operation on a domain controller of
the current domain.
/ADD Adds a user account to the user accounts database.
/DELETE Removes a user account from the user accounts database.
Options Are as follows:
Options Description
--------------------------------------------------------------------
/ACTIVE:{YES | NO} Activates or deactivates the account. If
the account is not active, the user cannot
access the server. The default is YES.
/COMMENT:"text" Provides a descriptive comment about the
user's account (maximum of 48 characters).
Enclose the text in quotation marks.
/COUNTRYCODE:nnn Uses the operating system country code to
implement the specified language files for a
user's help and error messages. A value of
0 signifies the default country code.
/EXPIRES:{date | NEVER} Causes the account to expire if date is
set. NEVER sets no time limit on the
account. An expiration date is in the
form mm/dd/yy or dd/mm/yy, depending on the
country code. Months can be a number,
spelled out, or abbreviated with three
letters. Year can be two or four numbers.
Use slashes(/) (no spaces) to separate
parts of the date.
/FULLNAME:"name" Is a user's full name (rather than a
username). Enclose the name in quotation
marks.
/HOMEDIR:pathname Sets the path for the user's home directory.
The path must exist.
/PASSWORDCHG:{YES | NO} Specifies whether users can change their
own password. The default is YES.
/PASSWORDREQ:{YES | NO} Specifies whether a user account must have
a password. The default is YES.
/PROFILEPATH[:path] Sets a path for the user's logon profile.
/SCRIPTPATH:pathname Is the location of the user's logon
script.
/TIMES:{times | ALL} Is the logon hours. TIMES is expressed as
day[-day][,day[-day]],time[-time][,time
[-time]], limited to 1-hour increments.
Days can be spelled out or abbreviated.
Hours can be 12- or 24-hour notation. For
12-hour notation, use am, pm, a.m., or
p.m. ALL means a user can always log on,
and a blank value means a user can never
log on. Separate day and time entries with
a comma, and separate multiple day and time
entries with a semicolon.
/USERCOMMENT:"text" Lets an administrator add or change the User
Comment for the account.
/WORKSTATIONS:{computername[,...] | *}
Lists as many as eight computers from
which a user can log on to the network. If
/WORKSTATIONS has no list or if the list is *,
the user can log on from any computer.
NET HELP command | MORE displays Help one screen at a time.
коротко принцип добавления примерно такой
C:\> NET USER vasia parolvasi /ADD /DOMAIN
ну а дальше, чтобы не колупатся с каждым индивидуаьно пишем два батника
start.bat - Файл, который вытаскивает построчно все значения и скармливает другому файлу
@for /f "tokens=1,2,3,4,5 delims=<tab>" %%a in (logins.txt) do @process.bat %%a %%b %%c %%d %%e
process.bat - Файл который принимает параметры от первого и занимается непосредственно добавлением пользователей
@set _login=%1
@set _pass=%2
@set _fname=%3
@set _lname=%4
@set _expdata=%5
@set _expdata_g=%_expdata:~7,4%
@set _expdata_m=%_expdata:~12,2%
@set _expdata_d=%_expdata:~15,2%
@echo %_fname% %_lname% %_login% %_pass% %_expdata_d%-%_expdata_m%-%_expdata_g%
вывод будет примерно такой
C:\tmp\bat>start.bat
name1 lastname1 login1 pass1 1-11-2007
name2 lastname2 login2 pass2 2-11-2007
name3 lastname3 login3 pass3 3-11-2007
name4 lastname4 login4 pass4 4-11-2007
name5 lastname5 login5 pass5 5-11-2007
name6 lastname6 login6 pass6 6-11-2007
name7 lastname7 login7 pass7 7-11-2007
name8 lastname8 login8 pass8 8-11-2007
name9 lastname9 login9 pass9 9-11-2007
name10 lastname10 login10 pass10 10-11-2007
name11 lastname11 login11 pass11 11-11-2007
name12 lastname12 login12 pass12 12-11-2007
name13 lastname13 login13 pass13 13-11-2007
name14 lastname14 login14 pass14 14-11-2007
name15 lastname15 login15 pass15 15-11-2007
name16 lastname16 login16 pass16 16-11-2007
Собственно говоря последняя строка заменяется на команду net user и дальше занимается только переносом пользователей из общего OU users в какуюто конкретную, так сказать порядок наводим