How to bulk rename active directory user objects

Posted on 2009-05-28
Medium Priority
Last Modified: 2013-12-23
I need to rename active directory user objects. For example the user account is called ai1 and the first name, last name and display name is Albert Einstein. I need the user account to be seen as Albert Einstein. I also need to do this for hundreds of account all at once.

Does anyone have any solutions.
Question by:Colin_A_Moulder
1 Comment
LVL 38

Accepted Solution

Shift-3 earned 2000 total points
ID: 24493072
Paste the script below into a text file with a .cmd extension.  Customize the value of the root variable on line 4 with the distinguished name of the domain or OU to search under.  Running the script on a 2003 server or XP workstation with the adminpak installed will echo DSMOVE commands to rename each user to the value of their Display Name.

Once you have tested it successfully and are sure it will do what you intend, remove the word ECHO from line 12 to execute the commands.

@echo off
setlocal enabledelayedexpansion
set root=ou=Accounting,DC=yourdomain,dc=local
for /F "tokens=*" %%G in ('dsquery user "%root%" -limit 0 ^| dsget user -dn -display -L') do (
 set line=%%G
 if "!line:~0,3!"=="dn:" set dn=!line:~4!
 if "!line:~0,8!"=="display:" if "!line:~9!" NEQ "" (
  set display=!line:~9!
  ECHO dsmove "!dn!" -newname "!display!" -q

Open in new window


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

A brief overview to explain gateways, default gateways and static routes OR NO - you CANNOT have two default gateways on the same server, PC or other Windows-based network device. In simple terms a gateway is formed when a computer such as a serv…
I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question