如何使用c#更新Active Directory属性。 [英] How to Update Active Directory attributes using c#.
问题描述
如何使用c#更新活动目录属性。就我而言,我有以下情况。对于每个用户,AD中都有一个 WhenCreated
属性,但是我想要的是,如果 whenDate
小于30天将活动目录中的 info
属性设置为 NEW
。
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.
如何通过c#逐步执行此操作。
How can I do this via c# step by step.
推荐答案
使用 DirectoryEntry 。在线上有很多使用它的示例。
Use DirectoryEntry. There are lots of examples online on how to use it.
一旦将DirectoryEntry对象绑定到AD对象,就可以设置如下属性:
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();
如果需要搜索对象,可以使用 DirectorySearcher 。您可以在此处看到示例,
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.
这篇关于如何使用c#更新Active Directory属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!