Jak pobrać wszystkich użytkowników z Active Directory?
Jestem nowy w asp.net, mam nowe zadania do pobrania wszystkich użytkowników z Active Directory. Gdy próbowałem pobrać wszystkich użytkowników z Active Directory, dostałem tylko jednego użytkownika.
private void btngetuser_Click(object sender, EventArgs e)
{
DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = string.Format(CultureInfo.InvariantCulture, "(sAMAccountName={0})", Environment.UserName);
//SearchResult findUser = searcher.FindOne();
foreach (SearchResult findUser in searcher.FindAll())
{
if (findUser != null)
{
DirectoryEntry user = findUser.GetDirectoryEntry();
string userName = user.Properties["displayName"].Value.ToString();
string Email = user.Properties["mail"].Value.ToString();
string Mobile = user.Properties["Mobile"].Value.ToString();
string Login = user.Properties["sAMAccountName"].Value.ToString();
string[] rt = new string[] { Login, userName, Email, Mobile };
dataGridView1.Rows.Add(rt);
}
}
}