Solved

Change AD attributes of a User using vbs script

Posted on 2007-03-26
6
650 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now