Announcement

Collapse
No announcement yet.

How to modify user attribute

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to modify user attribute

    Hi to all

    environment : Windows 2000 Active Directory
    I'd to change the "department" attribute for some users and replace it with the "extensionAtrribute1" of the same user.
    I try to do this with ADModify but unsuccessfully.

    Some ideas
    Thanks

    Ari

  • #2
    Cross posting, ah ?

    Code:
    On Error Resume Next
    
    Dim objCont
    Dim strLDAPBase
    strLDAPBase="ou=Accounts,dc=domain,dc=com"
    
    Set objCont = GetObject("LDAP://" & strLDAPBase)
    
    EnumerateCont objCont
    
    'Clean up
    Set objCont=Nothing
    WScript.Quit(0)
    
    
    '==========================================
    '                        Subroutines
    '==========================================
    
    Sub EnumerateCont(oCont)
            Dim oObj
            Dim strSourceAttr
            For Each oObj In oCont
                    Select Case LCase(oObj.Class)
                            Case "user"
                                    strSourceAttr = oObj.Get("extensionAtrribute1")
                                    oObj.Put "department", strSourceAttr
                                    oObj.SetInfo
                                           If Err.Number <> 0 Then
                                             Wscript.Echo "Unable to set attribute department of user " & 
    oObj.Get("userPrincipalName") & " to " & strSourceAttr
                                             Wscript.Quit
                                            End If
                                    
                            Case "organizationalunit" , "container"
                                    EnumerateCont oObj
                    End Select
            Next
    End Sub
    Guy Teverovsky
    "Smith & Wesson - the original point and click interface"

    Comment


    • #3
      Hi Guy
      I replace the strLDAPBase with the rihgt parameter. I try the script but nothing occurs.

      Can you help me ?

      Ari

      Comment


      • #4
        Hi Guy

        I find another way to do this. I use the ADModify utility (dos command)

        admodcmd -dn OU=MyOU,DC=domain,DC=com -custom departme
        nt 'extensionAttribute1'

        and it works very well

        Ari

        Comment


        • #5
          Originally posted by Ari
          Hi Guy
          I replace the strLDAPBase with the rihgt parameter. I try the script but nothing occurs.

          Can you help me ?

          Ari
          any errors?
          Marcel
          Technical Consultant
          Netherlands
          http://www.phetios.com
          http://blog.nessus.nl

          MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
          "No matter how secure, there is always the human factor."

          "Enjoy life today, tomorrow may never come."
          "If you're going through hell, keep going. ~Winston Churchill"

          Comment


          • #6
            I had a typo in the script. The extensionAttribute1 was not spelled right.

            If anyone is interested, here is the updated version:
            Code:
            On Error Resume Next
            
            Const E_ADS_PROPERTY_NOT_FOUND = &H8000500D
            
            Dim objCont
            Dim strLDAPBase
            strLDAPBase="ou=mailrelay,dc=antid0t,dc=net"
            
            Set objCont = GetObject("LDAP://" & strLDAPBase)
            
            EnumerateCont objCont
            
            'Clean up
            Set objCont=Nothing
            WScript.Quit(0)
            
            
            '==============================================================
            ' Subroutines
            '==============================================================
            
            Sub EnumerateCont(oCont)
            Dim oObj
            Dim strSourceAttr
            For Each oObj In oCont
            	Select Case LCase(oObj.Class)
            		Case "user"
            			wscript.echo "Processing: " & oObj.name
            			On Error Resume Next
            			Err=0
            			strSourceAttr = oObj.Get("extensionAttribute1")
            			If Err = E_ADS_PROPERTY_NOT_FOUND Then
            				wscript.echo "Object does not have extensionAttribute1 defined. Skipping..."
            			Else
            				oObj.Put "department", strSourceAttr
            				oObj.SetInfo
            			End If
            
            		Case "organizationalunit" , "container"
            			EnumerateCont(oObj)
            	End Select
            Next
            End Sub
            Guy Teverovsky
            "Smith & Wesson - the original point and click interface"

            Comment


            • #7
              Hi Guy

              Thanks for your help

              Ari

              Comment


              • #8
                guy,

                can you move this post to the scripting forum where it belongs?
                Marcel
                Technical Consultant
                Netherlands
                http://www.phetios.com
                http://blog.nessus.nl

                MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
                "No matter how secure, there is always the human factor."

                "Enjoy life today, tomorrow may never come."
                "If you're going through hell, keep going. ~Winston Churchill"

                Comment

                Working...
                X