Solved

Modifying AD username

Posted on 2015-01-07
6
56 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
[X]
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
  • 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 AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial 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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

728 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