Copy an AD attribute to another AD attribute

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
mylastknight
Posts: 1
Joined: Thu Jun 28, 2012 4:49 am

Copy an AD attribute to another AD attribute

Post by mylastknight » Thu Jun 28, 2012 4:52 am

Does anyone have an example script that copies an AD Attribute to another Attribute and will do this for all objects in AD? I would also like the changeds output to a log file.

Specifically, I need to copy the ipphone attribute to extensionAttribute 12 for all users and log the output to a file. I would be greatful!!!!

Jamesmylastknight2012-06-28 11:55:19

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Copy an AD attribute to another AD attribute

Post by jvierra » Thu Jun 28, 2012 5:03 am

What are ALL OBJECTS? Do you want to copy all object properties to all object properties. That doesn't make any sense. All objects do not have the same attributes. Example: An OU soes not have a phone number or email address.


User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Copy an AD attribute to another AD attribute

Post by jvierra » Thu Jun 28, 2012 6:27 am

It just takes three lines.

set user = GetUser(LDAP://cn=user1,dc=serv,dc=dom,dc=com)
user.extensionAttribute12=user.ipphone
user.Setinfo


Just get all users and feed them to the code above.

Code: Select all

set OU =GetObject("LDAP://cn=users,dc=domain,dc=local")
OU.Filter="objectClass=user"
For each user in OU
    If user.class="user" Then
        On Error Resume Next
        user.extensionAttribute1=user.ipphone
        If Err.Number = 0 Then
             user.SetInfo
             WScript.Echo "Copied:" & user.ipphone & " for " & user.name 
        Else
             On Error GoTo 0
             WScript.Echo "No IPPHONE configured for " & user.name
        End If
        On Error GoTo 0
    End If
next

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Copy an AD attribute to another AD attribute

Post by jvierra » Thu Jun 28, 2012 6:55 am

Gets all users.
uploads/2491/GetAllUsers.txt

Locked