У меня есть следующий код для запроса AD с использованием DirectorySearcher
, чтобы получить все группы AD для пользователя.Запрос AD для поиска всех групп пользователей - Отсутствует одна группа
List<string> Groups = new List<string>();
//initialize the directory entry object
DirectoryEntry dirEntry = new DirectoryEntry(ldapPath);
//directory searcher
DirectorySearcher dirSearcher = new DirectorySearcher(dirEntry);
//enter the filter
dirSearcher.Filter = string.Format("(&(objectClass=user)(sAMAccountName={0}))", username);
//get the member of properties for the search result
dirSearcher.PropertiesToLoad.Add("memberOf");
int propCount;
SearchResult dirSearchResults = dirSearcher.FindOne();
propCount = dirSearchResults.Properties["memberOf"].Count;
string dn;
int equalsIndex;
int commaIndex;
for (int i = 0; i <= propCount - 1; i++)
{
dn = dirSearchResults.Properties["memberOf"][i].ToString();
equalsIndex = dn.IndexOf("=", 1);
commaIndex = dn.IndexOf(",", 1);
if (equalsIndex == -1)
{
return null;
}
if (!Groups.Contains(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1)))
{
Groups.Add(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1));
}
}
return Groups;
Но когда я проверить вкладку «memberof» в AD для пользователя Я одна дополнительная группа «Пользователи домена», который я не получаю через этот код.
Любые идеи? Почему я не получаю «Пользователи домена» в коллекции «memberof»?
Может быть основан на конфигурации сервера, в которой вы находитесь, и это роль/функция, см. В части memberOf этой страницы http://msdn.microsoft.com/en-us/library/ms677943 – curtisk
Okie. Я узнал отсюда: http://www.eggheadcafe.com/software/aspnet/30375857/directory-searcher-not-returning-all-groups.aspx, что memberOf не вернет первичные группы пользователей. Но я могу получить primaryGroupID, который дает RID (?) Группы, с помощью которой мне нужно получить группу AD. Есть идеи, как это сделать? – NLV