Solved

Change AD attributes of a User using vbs script

Posted on 2007-03-26
6
662 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

738 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