Link to home
Start Free TrialLog in
Avatar of yo_bee
yo_beeFlag for United States of America

asked on

Adding attribute values to <not set>

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

Open in new window

Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yo_bee


That works if there is a value already, but of the attribute is  this method does not seem to work.

There's no reason for it to fail. Does it return an error message?

Avatar of yo_bee


I do get an error, but at the present time I do not have it. When I am able to run this again I will post the error.
That would be good, thanks :)

Avatar of yo_bee


I do get an error, but at the present time I do not have it. When I am able to run this again I will post the error.
Avatar of yo_bee


The Put option worked fine.
No Errors
Could you help me with my second part of my questions?

Sure. Have you looked at System.Environment.GetCommandLineArgs?

The example on there is pretty good, it's not really any different from the example I'd give you. Does that go in the direction you need?

Avatar of yo_bee


Worked perfectly