Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logon name change 1

Status
Not open for further replies.

supportahm1980

Technical User
May 30, 2006
208
0
0
US
Hi. I am looking to change a OU worth of users from Jdoe to John.Doe format. I have the default e-mail recipient policy changed in exchange already.

The two fields I am looking to change is the User logon name and the userlogon name pre windows 2000. (which can be found on the Account tab in AD)

Are these fields the "SamAccountName" and "UserPrincipalName"

My idea is to grab each users first and last name and replace the two fields above with something like ObjUser.Put "UserPrincipalName", FirstName & "." & Surname & "@domain.local"

Thank you.
 
This is easy enough to accomplish.

Code:
'You only need to change the following text to match your OU structure
OUPath = "LDAP://OU=Test OU,DC=thespidersparlor,DC=local"

Set CNUsers = GetObject (OUPath)
CNUsers.Filter = Array("user")
For Each User in CNUsers
     NewNameFormat = User.givenName & "." & User.sn
     Set objUser = GetObject("LDAP://" & User.DistinguishedName)
     objUser.SamAccountName = NewNameFormat
     objUser.UserPrincipalName = NewNameFormat
     objUser.SetInfo
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks. I scripted like this:

Sub ModifyUsers(oObject)
Dim oUser
For Each oUser in oObject
Select Case oUser.Class
Case "user"

oUser.Put "UserPrincipalName", oUser.FirstName & "." & oUser.Lastname & "@foo.local"
oUser.Put "SamAccountName", oUser.FirstName & "." & oUser.Lastname
oUser.Setinfo

Case "organizationalUnit" , "container"
ModifyUsers(oUser)
End select
Next
End Sub
Dim oDomain
'Set OU below to employees when in production.

Set oDomain=GetObject("LDAP://OU=testusers,OU=test,DC=foo,DC=local")
ModifyUsers(oDomain)
Set oDomain = Nothing
MsgBox "Finished"
WScript.Quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top