Solved

Strip leading "s" from AD usernames

Posted on 2014-10-10
2
72 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:Stevenscs2
[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

Is Your AD Toolbox Looking More Like a Toybox?

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.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
In-place Upgrading Dirsync to Azure AD Connect
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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