Windows batch add AD domain account

Source: Internet
Author: User
Tags eol

Batch commands are required because you want to batch add domain users to Windows Server using a batch command.
I this is a pure novice tutorial, on Baidu search some batch processing command feel belongs to the Advanced tutorial, study two days to complete my goal.
Let's start with a little bit:

The batch BAT document is established.

Create a TXT document directly and then change the suffix to. bat, which is a bat document, double-click to run.
Note: Where is the bat file and where is his running path.
Add a successful user

The first way: command-line arguments are added

"cn=%1, ou=RadiusUser,dc=win218, dc=com" -upn %2@win218.com  -samid %2 -pwd %3 -display %4 -dept %5 -company %6 -office %7 -tel %8 -disabled no
    • 1

The following is an analysis of this statement:
dsadd user: Adding users to the domain
cn=%1: User name cn first parameter%1 This parameter is the first parameter that a user needs to enter when running a command
Ou=radiususer: Name of the storage folder
dc=win218, dc=com: domain name
-UPN%[email protected]: This is the login name added before the domain
-samid%2: This is actually a login name, but the version is different, so he and the above parameters are consistent
-PWD%3: Login Password
-display%4-dept%5-company%6-office%7-tel%8: This is the description of the inside information, put in a piece said, followed by: Display Name, Department, company, office, telephone.
-disabled No: The directly available account, if yes, is required to unlock the account to use.
Set the above command to a bat file and you can then run cmd to invoke the bat file. Because you need to pass in parameters, you cannot click the bat file directly for use. The following are:

This is the first place to go to your bat path, because my 2.bat is on the desktop so go to the desktop path, and then the first parameter is your bat name, which file you want to run, and then enter the parameters in turn. can be run. The user was successfully added.
Why would I do that? Because another person on the site to add users, each call my bat incoming parameters can be added users, he does not need to go to the ad domain one by one to add very convenient.

Second way: Read file Add user

I refer to this article win2008r2 AD User Bulk Import
, first create a file in CSV format

The following is the creation of the bat file
First we can look at how to view the CSV file displayed in the Command box

echo 查看文件信息for /f "tokens=1-7 delims=," %%a in (C:\Users\Administrator.WIN-LS3G942M36M\Desktop\test.csv) do @echo %%a %%b %%c %%d %%e %%f %%gpause
    • 1
    • 2
    • 3

echo indicates that the command line to be displayed is almost paused with System.out in Java, and if you do not pause, the command line runs out and disappears.
Post-run Effects:

for /f "skip=1 eol=;tokens=1-7 delims=," %%a in (C:\Users\Administrator.WIN-LS3G942M36M\Desktop\test.csv) do dsadd user "cn=%%a,ou=RadiusUser,dc=win218, dc=com" -upn %%b@win218.com -samid %%b -pwd %%c -display %%a -dept %%f -company %%e -office %%f -tel %%g -disabled no
    • 1

Skip=1 eol=;tokens=1-7 delims=,: Indicates that the first line of text is skipped because the first row is the caption. Tokens indicates a total of seven keywords
%%a in (C:\Users\Administrator.WIN-LS3G942M36M\Desktop\test.csv): two% is because the alphabetic parameter in the batch command requires a climbed semicolon, and only one is required on the command line. The file path to be read is in parentheses.
Do dsadd user "cn=%%a,ou=radiususer,dc=win218, dc=com": Add users, parameter a,b,c corresponding to the position of the parameters in the text.
In this way, you only need to enter the user you want to add in the Excel file, and then execute the bat file to add the user in bulk at once.

Both of these methods can be added in bulk users for different situations.

Windows batch add AD domain account

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.