Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Modifying AD username

Posted on 2015-01-07
6
53 Views
Last Modified: 2015-01-12
I am moving over 200 users to a different site and changing OU's so I also need to change their SAMAccount name as well. For example John Doe in Baltimore, MD would be BALJDoe and he will move to Portland, OR and gets renamed to PORJDoe. I don't want to change the AD account one by one. What's the best way to do this for over 200 users?
0
Comment
Question by:CiscoAzn
  • 3
  • 3
6 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40536054
Most effective way is with powershell.

Create a CSV file with the following headings...
CurrentSAM   NewSAM
johndoe           BALjdoe
etc...

Once you have your CSV file created use the following script to change all of the users sAMAccountNames
import-module activedirectory
$UserMod = import-csv "c:\yourcsvhere.csv"
foreach ($entry in $UserMod) {
$entry.CurrentSAM
$entry.NewSAM
Get-Aduser -Identity $entry.CurrentSAM | Set-Aduser -sAMAccountName $entry.NewSAM
}

Open in new window


The above code will go through each on in the list and update the sAMAccountName to the New one you have listed in the csv file.

Will.
0
 

Author Comment

by:CiscoAzn
ID: 40536068
Can you specify in the code to point to a particular OU where all these users are in?
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40536136
When you use the get-aduser cmdlet you do not need to specify the OU that the users resides.

You can also just add 1 user to the csv file, then run the script and ensure that no errors come back.

Will.
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:CiscoAzn
ID: 40545233
This changes the pre-Windows 2000 name but not the actual logon name.
0
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 500 total points
ID: 40545242
If you also want the UPN (name@domain,com) you will need to add another column to the CSV file and use the below code...

CSV file format
CurrentSAM   NewSAM      NewUPN
johndoe           BALjdoe      BALjdoe@domain.com
etc...

import-module activedirectory
$UserMod = import-csv "c:\yourcsvhere.csv"
foreach ($entry in $UserMod) {
$entry.CurrentSAM
$entry.NewSAM
$entry.NewUPN
Get-Aduser -Identity $entry.CurrentSAM | Set-Aduser -sAMAccountName $entry.NewSAM -UserPrincipalName $entry.NewUPN
}

Open in new window


Will.
0
 

Author Closing Comment

by:CiscoAzn
ID: 40545324
Worked perfectly. Thanks for the help.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

860 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