Solved

Strip leading "s" from AD usernames

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
A procedure for exporting installed hotfix details of remote computers using powershell
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…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

840 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