2013-11-24 148 views
0

我试图从Active Directory获取主目录的属性值“主目录”属性..从Active Directory获取

我用下面的代码:

public static void GetExchangeServerByWwidLdap(string wwid) 
{ 
    var exchange = string.Empty; 

    using (var ds = new DirectorySearcher()) 
    { 
     ds.SearchRoot = new DirectoryEntry("GC:something"); 
     ds.SearchScope = SearchScope.Subtree; 

     //construct search filter 
     string filter = "(&(objectclass=user)(objectcategory=person)"; 
     filter += "(employeeid=" + wwid + "))"; 
     ds.Filter = filter; 

     string[] requiredProperties = new string[] { "homeDirectory", "homemta" }; 

     foreach (String property in requiredProperties) 
      ds.PropertiesToLoad.Add(property); 

     SearchResult result = ds.FindOne(); 
    }  
} 

当我检查result对象数据,我只看到2个值:“homemta”和“adspath”。 “homeDirectory”值在哪里?

我进入AD网站和搜索相同的用户相同的价值观 - 通过网站,我可以看到我的所有搜索,所以我假设我的代码问题的地方的数据。

我在做什么错?

回答

0

你正在尝试从全局编录homeDirectory的。

It’s not there.

你可以如通过ADsPath属性(即“LDAP:// ...”字符串)绑定到用户,然后查询该用户的homeDirectory属性。

或者,如果你只有一个域,你可以把该领域,而不是搜索的GC内进行搜索。在这种情况下,您将能够检索所有您想要的属性。

相关问题