Solved

Strip leading "s" from AD usernames

Posted on 2014-10-10
2
64 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
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
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…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

914 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

17 Experts available now in Live!

Get 1:1 Help Now