我以前没有使用过 LDAP,所以我有点迷失。我需要连接到 LDAP 源查找特定属性并更改它。该程序的输入是一个包含用户列表的 CSV 文件。该程序应该从 CSV 文件中读取 UID,找到 LDAP 中的记录并替换某个属性。我不知道如何做到这一点。有人能给我指出正确的方向吗?
@KenL 差一点就到了。我还必须设置 AuthenticationType目录项 http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.aspx让它发挥作用。另外,请注意如何使用通配符(克林星 https://en.wikipedia.org/wiki/Kleene_star).
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://some.ldap.server.com");
rootEntry.AuthenticationType = AuthenticationTypes.None; //Or whatever it need be
DirectorySearcher searcher = new DirectorySearcher(rootEntry);
var queryFormat = "(&(objectClass=user)(objectCategory=person)(|(SAMAccountName=*{0}*)(cn=*{0}*)(gn=*{0}*)(sn=*{0}*)(email=*{0}*)))";
searcher.Filter = string.Format(queryFormat, searchString);
foreach(SearchResult result in searcher.FindAll())
{
Console.WriteLine("account name: {0}", result.Properties["samaccountname"].Count > 0 ? result.Properties["samaccountname"][0] : string.Empty);
Console.WriteLine("common name: {0}", result.Properties["cn"].Count > 0 ? result.Properties["cn"][0] : string.Empty);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)