John Champion
John Champion

Reputation: 147

How to Update Active Directory attributes using c#.

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.

Upvotes: 5

Views: 15942

Answers (1)

Gabriel Luci
Gabriel Luci

Reputation: 40938

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.

Upvotes: 10

Related Questions