Solved

Modifying AD username

Posted on 2015-01-07
6
52 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Problems using Powershell and Active Directory?

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

Question has a verified solution.

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

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now