Solved

Change AD attributes of a User using vbs script

Posted on 2007-03-26
6
659 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:dion_p1
  • 3
  • 2
6 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18791657
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
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18791661
Oops - left out a requirement..

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.cn=strLN & " " & strFN
  objUser.SetInfo
Next
0
 

Author Comment

by:dion_p1
ID: 18796162
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
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18796273
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
0
 
LVL 2

Expert Comment

by:remtech75
ID: 18820321
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)

0
 

Author Comment

by:dion_p1
ID: 18831619
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...
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

792 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