Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change AD attributes of a User using vbs script

Posted on 2007-03-26
6
Medium Priority
?
666 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
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 …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

715 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