In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use scripts to solve the problem of batch operation of AD users. I hope you will get something after reading this article. Let's discuss it together.
1. Suppose there are 1000 users in an enterprise (DC is www.gr.com, the following is the same), among which there are 100 users who contain user characters, and they are divided in different OU, such as: IT,PM,MRP,ACC, etc., now that we have created a new OU named Sales, how do we move these 100 users from other OU to Sales this OU?
Answer:
Dsquery user-name * user* > > c:\ user.txt
For / f% I in (c:\ user.txt) do dsmove% I-newparent ou=Sales,dc=www,dc=gr,dc=com
two。 Suppose there are 1000 users in an enterprise, of whom 100 belong to the Sales group, which are divided into different OU, such as IT,PM,MRP,ACC, and so on. Now that we have created a new OU named Sales, how do these users who belong to the Sales group move to the OU of Sales from other OU?
Answer:
Dsget group "cn=Sales,cn=users,dc=www,dc=gr,dc=com"-members > > c:\ user.txt
For / f% I in (c:\ user.txt) do dsmove% I-newparent ou=Sales,dc=www,dc=gr,dc=com
3. Suppose an enterprise has 100 new employees assigned to the IT,PM,MRP,ACC,Sales department. Now how do you batch up these users and set up their group and OU?
Answer:
First, create a c:\ userlist.csv in the following format:
HenGong,ACC,p@ssw0rd
ChengYuanZhi,IT,p@ssw0rd
ChengPu,MRP,p@ssw0rd
FOR / F "eol=; tokens=1,2,3* delims=,"% an in (c:\ userlist.csv) do dsadd user "cn=%a,ou=%b,dc=www,dc=gr,dc=com"-pwd% c-samid% a-upn% a@www.gr.com
4. For a long time, due to staff turnover and other reasons, more and more users are disabled in AD, and their branches are in different OU, how to delete these disabled users in batches?
Answer:
Dsquery user-disabled > > c:\ user.txt
For / f% I in (c:\ user.txt) do dsrm-noprompt-c "% I"
Summing up the above questions, I wrote a script that we can easily achieve the above functions.
The script is as follows, you can copy it to notepad and save it in cmd format, or you can download the file I uploaded and change its suffix to cmd and csv respectively, in which the test DC I used in this script is www.gr.com, please try to change the corresponding part of the script to your own DC.
@ echo off
Cls
Cd\
C:
Echo.
Echo
Echo this script is used to change the OU of AD users and set up users in batches.
Echo
Echo.
Echo [1] batch changes from user to new OU
Echo [2] change the same group of users to the new OU
Echo [3] set up users in batch
Echo [4] batch deletion of disabled users
Echo
Echo.
Set / p select= Please select from the menu:
If "% select%" = = "1" set / p username= Please enter the desired lookup user (match can be used): & goto A
If "% select%" = = "2" set / p groupname= Please enter the desired lookup group name: & goto B
If "% select%" = = "3" goto D
If "% select%" = = "4" goto E
: A
Dsquery user-name% username% > > user.txt
Echo.
Echo--
Echo successfully exported the matching user information.
Echo--
Goto C
: B
Dsget group "cn=%groupname%,cn=users,dc=www,dc=gr,dc=com"-members > > user.txt
Echo.
Echo--
Echo successfully exported user information for group groupname%.
Echo--
Goto C
: C
Echo.
Set / p ouname= Please enter the OU to which the user needs to update:
For / f% I in (user.txt) do dsmove% I-newparent ou=%ouname%,dc=www,dc=gr,dc=com
Echo.
Echo--
Echo has successfully updated the user to% ouname% OU. Thank you for using it.
Echo--
Echo.
Goto Z
: D
Set / p userpath= Please enter the user list file path (c:\ userlist.csv):
FOR / F "eol=; tokens=1,2,3* delims=," an in (% userpath%) do dsadd user "cn=%%a,ou=%%b,dc=www,dc=gr,dc=com"-pwd% c-samid% a-upn% a@www.gr.com
Echo.
Echo
Echo has successfully created a user in the% userpath% list. Thank you for using it.
Echo
Echo.
Goto Z
: E
Set / p select= are you sure to delete the disabled user? (YPEA):
If "% select%" = = "y" goto F
If "% select%" = = "n" goto Z
: F
Dsquery user-disabled > > user.txt
For / f% I in (user.txt) do dsrm-noprompt-c "% I"
Echo.
Echo--
Echo has successfully deleted the disabled user. Thank you for using it.
Echo--
Echo.
: Z
Del user.txt
Pause
Echo on
After reading this article, I believe you have a certain understanding of "how to use scripts to solve the problem of batch operation of AD users". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.