2012-01-03 31 views
0

所以我設法得到一些代碼滾動更新從外部來源的廣告。但是,我對它的工作原理有些困惑。 我有一個人sAMAccount xxxx存在於不同的OU中。 現在,我只想更新特定OU中的信息,所以我將它放在我的LDAP路徑中。不過,這些信息似乎已經在不同的OU中更新過了?更新用戶使用DirectoryService

這可能嗎?是因爲只有一個「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對象。因此,Person對象在整個AD中都是一樣的,這使得我試圖只在特定的OU中毫無意義地更新它們,或者「result.GetDirectoryEntry」忽略了我認爲我只在我的特定OU在我的LDAP路徑中聲明。

回答

0

功能確認,仍然奇怪爲什麼我需要一個特定的測試 - ou,因爲它仍然是相同的用戶。無論如何,我們走吧!