Solved

Strip leading "s" from AD usernames

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

Accepted Solution

by:
becraig earned 250 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
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 walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
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…

744 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