Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Adding attribute values to <not set>

Avatar of yo_bee
yo_beeFlag for United States of America asked on
DatabasesActive DirectoryVB Script
9 Comments1 Solution1401 ViewsLast Modified:
I am trying to setup a VB console app so I can schedule certain updateds to users Attributes.
I have created a simple script that queries all the user and if the CN matches the user it will update the altRecipient attribute from <not set> to a ADsPath.
I am able to clear the attribute, but not able to update.

I was also trying to add arg so I can run this without modifying the code, but this is the second part.  I need to get the first part to work. ;)

Imports System.Text.RegularExpressions
Imports System.DirectoryServices

Module Module1

    Sub Main()

        Const ADS_PROPERTY_CLEAR = 1
        Const ADS_PROPERTY_UPDATE = 2
        Const ADS_PROPERTY_APPEND = 3
        Const ADS_PROPERTY_DELETE = 4


        Dim objRootDSE
        Dim objSchemaContainer
        Dim strSchemaPath
        'Get the Root DSE from a random DC'
        objRootDSE = GetObject("LDAP://RootDSE")
        'Get the Schema NC path for the domain'
        strSchemaPath = objRootDSE.Get("defaultNamingContext")
        'Connect to the schema container on a random DC'
        objSchemaContainer = GetObject("LDAP://" & strSchemaPath)

        Dim objSearch As New DirectorySearcher()
        objSearch.SearchRoot = New DirectoryEntry(objSchemaContainer)
                objSearch.Filter = "(&(objectCategory=user))" 
        objSearch.SearchScope = SearchScope.Subtree

        Dim colQueryResults As SearchResultCollection
        colQueryResults = objSearch.FindAll()
        Dim objResult As SearchResult
        For Each objResult In colQueryResults
            If objResult.Properties("cn")(0) = "<username>" Then
                Dim ObjUser As Object
                Dim StrAtt As String
                StrAtt = objResult.Properties("ADsPath")(0)
                ObjUser = GetObject(StrAtt)
                ObjUser.Putex(ADS_PROPERTY_CLEAR, "altRecipient", "CN=<username>,OU=IT Staff,DC=<domain>,DC=local"))

            End If


    End Sub


End Module
Avatar of Chris Dent
Chris DentFlag of United Kingdom of Great Britain and Northern Ireland imagePowerShell Developer
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answers