Scripting an OU to reverse Last Name, First Name to First Name Last Name

Discussion in 'Scripting' started by debra.dorn, Aug 26, 2004.

  1. debra.dorn

    debra.dorn Guest

    Our AD is set up as First Name Last Name. We have to
    import 500 users from another company and their's is set
    up Last Name, First Name. This creates a problem in our
    GAL. I have been having problems creating the script to
    switch this. Has anyone scripted something like this and
    if so, what are the proper commands?
     
    debra.dorn, Aug 26, 2004
    #1
    1. Advertisements

  2. "" <> a écrit dans
    le message de | Our AD is set up as First Name Last Name. We have to
    | import 500 users from another company and their's is set
    | up Last Name, First Name. This creates a problem in our
    | GAL. I have been having problems creating the script to
    | switch this. Has anyone scripted something like this and
    | if so, what are the proper commands?

    .... As I understood you need to swap user FirstName and LastName how it
    appears in the Active Directory Users and Computers OU list ...That means
    you need to change the "name" attribute of the user account ...AFAIK you
    cannot do it on the existing account ....A solution may be like this ...You
    put all users being imported in an OU, say SourceOU, then run a script over
    the OU which reads users attributes, swaps FirstName and LastName on the fly
    then deletes the user account in the SourceOU and creates a new User with
    the same attributes and reversed name in a new OU, say TargetOU ....A sample
    script for doing this is below ...

    Set trgOU = GetObject("LDAP://ou=TargetOU,dc=company,dc=com")
    Set srcOU = GetObject("LDAP://ou=SourceOU,dc=company,dc=com")
    For Each objUser In srcOU
    strSAMAccountName = objUser.Get("sAMAccountName")
    strName = objUser.Get("name")
    arrName = Split(strName, " ")
    strReversedName = arrName(1) & " " & arrName(0)
    strLogonName = objUser.Get("userPrincipalName")
    srcOU.Delete "user", "cn=" & strName
    Set newUser = trgOU.Create("user", "cn=" & strReversedName)
    newUser.Put "sAMAccountName", strSAMAccountName
    newUser.Put "userPrincipalName", strLogonName
    newUser.SetInfo
    Next

    .....this creates just an account with minimum attributes ...You can however
    add necessary lines to get other attributes from the old account (before
    deleting it) and to put them into the new one ....
     
    Yevgen Lazaryev, Sep 2, 2004
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.