Solved

Strip leading "s" from AD usernames

Posted on 2014-10-10
2
76 Views
Last Modified: 2014-10-20
We have a leading "s" on all student active directory usernames. Is there a quick way to strip that off?
0
Comment
Question by:Steven S
[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
2 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 250 total points
ID: 40373195
I am hoping your users are all in the same OU and this is a hard and fast rule, since you could change "samanthar" or some other such user if you are just replacing the first letter if it is an "S"

import-module ac*
$users = get-aduser -filter * -searchbase (if applicable) "OU=OU..."
foreach ($user in $users) 
{
if (user.SamAccountName.Substring(0,1) -eq "s"){
    $newSamAccoutname = $user.SamAccountName.Substring(1)
    Set-ADUser $user -Replace @{samaccountname=$newSamAccoutname} 
}
}

Open in new window

0
 
LVL 7

Assisted Solution

by:CorinTack
CorinTack earned 250 total points
ID: 40373208
It would be a multiple step process, but you could use Powershell to accomplish this. First, you'll need to export a list of all the student usernames out of Active Directory: http://www.cmsconnect.com/praetor/webhelpg2/chapter_7_-_log_viewer/ad_export_users.htm

Then, you'll want to create a PowerShell script.

In that script, you'll import the list you got (in CSV format): http://technet.microsoft.com/en-us/library/ee176874.aspx

Then you'll have to pipe the results of that into a line that uses the ForEach property.

For each user, you'll need to use the command Set-ADUser: http://technet.microsoft.com/en-us/library/ee617215.aspx

Within Set-ADUser, you'll set the sAMAccountName property to what you want.

That's the best way to accomplish this. As an example, let's say you export the users into a CSV called students.csv. Your header for the students' current user names was Alias, and you created a new column called NewName with the new user names for the students. Then your script would look like this:

Import-module ActiveDirectory
Import-CSV "C:\students.csv" | foreach {Set-ADUser -Identity $_.Alias sAMAccountName $_.NewName}

Open in new window

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

623 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