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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
I used this path LDAP://OU=Year 07,OU=Students,DC=company,
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.ads Path)
strFN=objUser.givenName
strLN=objUser.sn
objUser.givenName=strLN
objUser.sn=strFN
objUser.cn=strLN & " " & strFN
objUser.SetInfo
Next
Set objOU=GetObject("LDAP://OU
objOU.Filter=Array("User")
For Each user in objOU
wscript.echo "Processing " & user.adsPath
set objUser=GetObject(user.ads
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("DefaultNam ingContext ")
WScript.Echo (strDomain)
You dit replace his "OU=Students,DC=company,DC
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("DefaultNam
WScript.Echo (strDomain)
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...
objUser.displayname=strLN & " " & strFN
It worked fine after that change...
Set objOU=GetObject("LDAP://OU
objOU.Filter=Array("User")
For Each user in objOU
set objUser=GetObject(user.ads
strFN=objUser.givenName
strLN=objUser.sn
objUser.givenName=strLN
objUser.sn=strFN
objUser.SetInfo
Next