Link to home
Start Free TrialLog in
Avatar of dion_p1
dion_p1

asked on

Change AD attributes of a User using vbs script

I need to create a script that will change three attributes of all the users found in a specific AD OU For me.

The OU is "Year 07"

The attributes i need to change are as follows....

I need to Get the Users Firstname, Last Name

Then I need to set the
Firstname = Lastname
Lastname = Firstname
Display Name = Firstname Lastname

As you can see i stuffed up the import of users and this is the easiest way i can do it.
Avatar of sirbounty
sirbounty
Flag of United States of America image

Here you go..

Set objOU=GetObject("LDAP://OU=Year 07,DC=company,DC=com")
objOU.Filter=Array("User")
For Each user in objOU
  set objUser=GetObject(user.adsPath)
  strFN=objUser.givenName
  strLN=objUser.sn
  objUser.givenName=strLN
  objUser.sn=strFN
  objUser.SetInfo
Next
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dion_p1
dion_p1

ASKER

It said cannot proform the requested operation on the RDN object.........

I used this path LDAP://OU=Year 07,OU=Students,DC=company,DC=com
Where'd you get that at? (which line?)

Set objOU=GetObject("LDAP://OU=Year 07,OU=Students,DC=company,DC=com")
objOU.Filter=Array("User")
For Each user in objOU
  wscript.echo "Processing " & user.adsPath
  set objUser=GetObject(user.adsPath)
  strFN=objUser.givenName
  strLN=objUser.sn
  objUser.givenName=strLN
  objUser.sn=strFN
  objUser.cn=strLN & " " & strFN
  objUser.SetInfo
Next
sirbounty's code seems ok to me, all credits to him !

You dit replace his "OU=Students,DC=company,DC=com" to your situation did you ? (just checking)
If it's a sub OU of your root domain, but you somehow don't know the name you can use this piece of code to find that out:

Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
WScript.Echo (strDomain)

Avatar of dion_p1

ASKER

I change one line of code that was sort of incorrect i wanted to change the displayname not the container name.

  objUser.displayname=strLN & " " & strFN

It worked fine after that change...