none
Updating Active Directory RRS feed

  • Question

  • So I have a script that updates AD I got from CodeProject. Works fine for any user if the attribute (i.e. mobile, telephoneNumber...) has an existing value and/or already exists.

    However, it looks like that if the attribute was not initially filled up in AD, it won't appear on the user's attribute list so the program fails an update.

    Any ideas?

    TIA

    Alex

            Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
            Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
            dirSearcher.Filter = "(&(SAMAccountName=" & userLogin & "))"
            dirSearcher.SearchScope = SearchScope.Subtree
            Dim searchResults As SearchResult = dirSearcher.FindOne()
            If Not searchResults Is Nothing Then
                Dim dirEntryResults As New DirectoryEntry(searchResults.Path)
                dirEntryResults.Properties("mobile")(0) = "1234567890"   <--- FAILS HERE 
                dirEntryResults.CommitChanges()
                dirEntryResults.Close()
                Exit Sub
            End If
    

    Friday, August 31, 2018 7:36 PM

Answers

  • OK this did the trick.

                dirEntryResults.Properties("mobile").Value = "1234567890"

    • Marked as answer by ARPRINCE Tuesday, September 4, 2018 1:48 PM
    Tuesday, September 4, 2018 1:48 PM

All replies

  • Im not sure that mobile is a collection. Try to drop the "(0)"

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Friday, August 31, 2018 7:45 PM
  • OK this did the trick.

                dirEntryResults.Properties("mobile").Value = "1234567890"

    • Marked as answer by ARPRINCE Tuesday, September 4, 2018 1:48 PM
    Tuesday, September 4, 2018 1:48 PM
  • youre welcome

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Tuesday, September 4, 2018 4:14 PM
  • Thanks for the response, appreciate it. See below dropping the "(0)" gives out an error.

    I was working on this since last Friday. I re-read the posting and found the answer within his scripts.

    Update AD



    • Edited by ARPRINCE Tuesday, September 4, 2018 4:46 PM
    Tuesday, September 4, 2018 4:45 PM