5

How can I update active directory attributes using c#. In my case I have the following case. For every user there is a WhenCreated attribute in AD, but what i want is, if the whenDate is less than 30 days set the info attribute to NEW in active directory.

How can I do this via c# step by step.

1 Answer 1

10

Use DirectoryEntry. There are lots of examples online on how to use it.

Once you have a DirectoryEntry object bound to an AD object, you can set an attribute like this:

de.Properties["info"].Value = "NEW";
de.CommitChanges();

If you need to search for object, you can use DirectorySearcher. You can see an example here, although there are plenty more online too.

Give it a try. If you run into problems, show us what you have.

Sign up to request clarification or add additional context in comments.

2 Comments

How come I got this error when try to modify property 'System.DirectoryServices.PropertyCollection.this[string]' cannot be assigned to -- it is read only
Because there was an error in my code :) I've updated it. You need to use .Value to read or assign the values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.