使用DirectoryService更新用户

时间:2012-01-03 12:20:49

标签: directoryservices

因此,我设法获得了一些代码,用于从外部源更新AD。但是,我对它是如何工作有点困惑。 我有一个人在不同的OU中存在sAMAccount xxxx。 现在,我只想更新特定OU中的信息,所以我把它放在我的LDAP路径中。不过,似乎信息已在不同的OU中更新了吗?

这可能吗?是因为只有一个“Person”对象,或者“GetDirectoryEntry()”没有把我放在树中的想法吗?或者..我只能想象,我看到的奇怪的东西是因为别的东西。

一些代码

            DirectoryEntry entry = new DirectoryEntry(LDAP://my.path/ou=myou, dc=my, dc=path);
            entry.Username = myUser
            entry.Password = myPass
            DirectorySearcher searcher = new DirectorySearcher(entry);
            searcher.Filter = @"(&(objectClass=Person)(SamAccountname=" + person.id + "))";
            SearchResult result = searcher.FindOne();

                    try
                    {
                        DirectoryEntry user = result.GetDirectoryEntry();
                        user.Properties["displayName"].Value = person.DisplayName;
                        user.Properties["givenName"].Value = person.Firstname;
                        user.CommitChanges();
                        user.Close();
                    }
                    catch (DirectoryServicesCOMException ex)

编辑:它确实更新了所有OU中的Person对象。因此,在整个AD中,Person对象是一个并且相同,这使我尝试仅在特定OU中无意义地更新它们,或者“result.GetDirectoryEntry”忽略了我认为我只在我的特定工作中这一事实OU在我的LDAP路径中声明。

1 个答案:

答案 0 :(得分:0)

功能已经确认,仍然想知道为什么我需要一个特定的测试 - 因为它仍然是相同的用户。无论如何,我们走吧!