Any automatic way of Renaming all user accounts to Employee IDs

E

eric hela

Hi guys help me,

I have been asked to rename all user accounts in AD to Employee IDs. Can
anyone share experience or an easy way of automating this process?. I have
over 2000 user accounts to replace in Windows 2000 AD. No other
information change will change. The only change will be to replace the
username to an Employee ID.



thanks
 
R

Richard Mueller

eric said:
I have been asked to rename all user accounts in AD to Employee IDs. Can
anyone share experience or an easy way of automating this process?. I
have over 2000 user accounts to replace in Windows 2000 AD. No other
information change will change. The only change will be to replace the
username to an Employee ID.

If you rename the account, you change the common name (the cn attribute).
However, may logon with their NT name, the "pre-Windows 2000 logon name",
which is the value of the sAMAccountName attribute. cn must be unique in the
container/OU, while sAMAccountName must be unique in the domain. Which are
you changing?
 
E

eric hela

Thanks Richard,

I wasn't aware of the difference and was thinking of only changing CN name.
Thinking for highlighting this fact. I will need help to change both to
Employee ID. In my case, the CN and sAMAccountName are same.

Thanks once again and wait again for your invaluable help.

Eric
 
R

Richard Mueller

Forgot to ask, is employeeID in Active Directory?

Best bet is to first dump all user Distinguished Names to a spreadsheet.
Then you can add columns as needed (with EmployeeID for example), plus
delete any users that should not be renamed (like Administrator). A program
to dump all user Distinguished Names to an Excel spreadsheet is linked here:

http://www.rlmueller.net/Create User List 3.htm

Another VBScript program can read user Distinguished Names from the
spreadsheet, rename the object, plus modify sAMAccountName to match. The
techniques for reading from the spreadsheet are demonstrated in the sample
program SetPWForUserList3.vbs linked on the page above. For your situation,
the loop that reads the spreadsheet might be similar to below, where I
assume the EmployeeID is in the second column, and the first row is skipped:
=============
intRow = 2
' Read rows from the spreadsheet until we encounter a blank in column 1.
Do While objSheet.Cells(intRow, 1).Value <> ""
' retrieve values from the spreadsheet.
strUserDN = objSheet.Cells(intRow, 1).Value
strEmployeeID = objSheet.Cells(intRow, 2).Value
' Bind to the user object.
On Error Resume Next
Set objUser = GetObject("LDAP://" & strUserDN)
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo "User NOT found: " & strUserDN
Else
On Error GoTo 0
' Bind to the parent container, the OU/container the user is in.
Set objParent = GetObject(objUser.Parent)
' To rename account, use MoveHere method. This changes the cn
attribute.
Set objNewUser = objParent.MoveHere(objUser.AdsPath, "cn=" &
strEmployeeID)
' Change the NT name of the user to match.
objNewUser.sAMAccountName = strEmployeeID
' Save the change to sAMAccountName.
objNewUser.SetInfo
End If
intRow = intRow + 1
Loop
===========
Even if employeeID is in Active Directory, you could dump it out in column 2
of the spreadsheet with the user DN in the first column. Better to see all
the users that will be renamed. Plus, you can test the second script on just
a few users before renaming all the rest.
 
E

eric hela

Richard,

This is invaluable. I appreciate your help very much. I will call again if
I need further assistance.

rgds
Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top