Solved

Modifying AD username

Posted on 2015-01-07
6
51 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
Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

707 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

16 Experts available now in Live!

Get 1:1 Help Now