C# 使用DirectorySearcher从大型广告组获取SamAccountName
我使用下面的方法来查询来自大型广告群的成员C# 使用DirectorySearcher从大型广告组获取SamAccountName,c#,asp.net,c#-4.0,active-directory,active-directory-group,C#,Asp.net,C# 4.0,Active Directory,Active Directory Group,我使用下面的方法来查询来自大型广告群的成员 try { DirectoryEntry entry = new DirectoryEntry("LDAP://CN=My Distribution List,OU=Distribution Lists,DC=Fabrikam,DC=com"); DirectorySearcher searcher = new DirectorySearcher(entry); searcher.Filter = "(objectClass=*
try
{
DirectoryEntry entry = new DirectoryEntry("LDAP://CN=My Distribution List,OU=Distribution Lists,DC=Fabrikam,DC=com");
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(objectClass=*)";
uint rangeStep = 1000;
uint rangeLow = 0;
uint rangeHigh = rangeLow + (rangeStep - 1);
bool lastQuery = false;
bool quitLoop = false;
do
{
string attributeWithRange;
if(!lastQuery)
{
attributeWithRange = String.Format("member;range={0}-{1}", rangeLow, rangeHigh);
}
else
{
attributeWithRange = String.Format("member;range={0}-*", rangeLow);
}
searcher.PropertiesToLoad.Clear();
searcher.PropertiesToLoad.Add(attributeWithRange);
SearchResult results = searcher.FindOne();
foreach(string res in results.Properties.PropertyNames)
{
System.Diagnostics.Debug.WriteLine(res.ToString());
}
if(results.Properties.Contains(attributeWithRange))
{
foreach(object obj in results.Properties[attributeWithRange])
{
Console.WriteLine(obj.GetType());
if(obj.GetType().Equals(typeof(System.String)))
{
}
else if (obj.GetType().Equals(typeof(System.Int32)))
{
}
Console.WriteLine(obj.ToString());
}
if(lastQuery)
{
quitLoop = true;
}
}
else
{
lastQuery = true;
}
if(!lastQuery)
{
rangeLow = rangeHigh + 1;
rangeHigh = rangeLow + (rangeStep - 1);
}
}
while(!quitLoop);
}
catch(Exception ex)
{
// Handle exception ex.
}
在这里,我想检索成员的SamAccountName以及他们的DiscrimitedName。此外,我还有一些包含跨域成员的组。请提供帮助。要获取任何属性的值,通常需要调用DirectoryEntry.Properties[PropertyName].value,例如
var x = results.Properties["distinguishedName"].Value
对于某些索引值,可能需要提供索引属性[PropertyName][X]。值
若结果中默认未填充值,则可能需要使用DirectorySearcher.PropertiesToLoad.Add(PropertyName)强制加载该值 如果有任何帮助,我们将不胜感激。你能发布你的最终版本吗?答案有用吗?