从活动目录检索数据 [英] retrieving data from active diractory

查看:80
本文介绍了从活动目录检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我创建了一个从活动目录获取所有用户的所有信息的功能
但我只知道名字,我很难获得其他信息
喜欢
我需要为所有用户获取此信息
名称,部门,电子邮件,显示名称,ou,分机,标题

你能告诉我怎么做吗这是我的代码


here i create a function to get all information of all users from active diractory
but i know to get only name i feel difficult to get other information
like
i need to get this information for all users
name, department, email, displayname, ou, ext, title

can u tell me how to do this here is my code


string[] properties = new string[] { "fullname" };
            try
            {

                dataGridView1.ColumnCount = 3;
                dataGridView1.Columns[0].Name = "Name";
                dataGridView1.Columns[1].Name = "Department";
                dataGridView1.Columns[2].Name = "Email";
                                               
                    DirectoryEntry entry = new DirectoryEntry("LDAP://asdd");
                    DirectorySearcher mySearcher = new DirectorySearcher(entry);
                    mySearcher.Filter = "(&(objectCategory=person)(objectClass=user))";
                    string[] propertiesToLoad = new string[1] { "samaccountname" };
                    string[] propertiesToLoad1 = new string[1] { "name" };
                    using (SearchResultCollection results = mySearcher.FindAll())
                    {
                        foreach (SearchResult result in results)
                        {                           
                            string name = (string)result.Properties["name"][0];
                            string email = (string)result.Properties["mail"][0];
                            dataGridView1.Rows.Add(new string[] { name,email});                           
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Problem in the server");
                }

推荐答案

尝试执行此操作以显示用户的所有属性.

Try this to show all properties for an user.

foreach (string var in result.Properties.PropertyNames)
{
  System.Diagnostics.Debug.WriteLine(string.Format("{0} : {1}", var, sr.Properties[var][0].ToString()));
}


这篇关于从活动目录检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆