• AD PropertiesToLoad


    以下方式若想改寫成抓取全部 , 想請教一些疑問

    撈出ActiveDirectory聯絡人

    按下button1 撈出單個使用者:

     private void button1_Click(object sender, EventArgs e)

            {

                string uid = "GGYY"//Domain帳號

                string pwd = "12345";  //密碼

                string domain = GetDomainName(domain_txt.Text);  //取得Domain

                string QueryString = "LDAP://" + domain;

                DirectoryEntry ldapConnection = new DirectoryEntry(QueryString, uid, pwd);   //使用DirectoryEntry  連入ActiveDirectory

                DirectorySearcher Searcher = new DirectorySearcher(ldapConnection);

                string value = string.Empty;

                string target = target_txt.Text;       

              try

                {

                     Searcher.Filter = "(SAMAccountName=" + target + ")";    //過濾條件  *有點搞不懂過濾的條件寫法該如何解釋,不知哪位大大能夠幫忙解釋

                     Searcher.PropertiesToLoad.Add("SAMAccountName");   //帳號

                     Searcher.PropertiesToLoad.Add("Name");   // 全名

                     Searcher.PropertiesToLoad.Add("displayName");   //ActiveDirectory的顯示名稱

                     Searcher.PropertiesToLoad.Add("mail");           //ActiveDirectory的信箱

                     Searcher.PropertiesToLoad.Add("description");

                     Searcher.PropertiesToLoad.Add("department");    //ActiveDirectory的信箱

                     Searcher.PropertiesToLoad.Add("company");

                     Searcher.PropertiesToLoad.Add("phsicalDeliveryOfficeName");

                     Searcher.PropertiesToLoad.Add("userPrincipalName");  //使用者帳號+Domain

                     Searcher.PropertiesToLoad.Add("telephoneNumber");       

                     Searcher.PropertiesToLoad.Add("givenName");  //first name

                     Searcher.PropertiesToLoad.Add("sn");

                    SearchResult result = Searcher.FindOne();       //若抓出全部使用者,應該是寫成這個方式 SearchResultCollection result = Searcher.FindAll( );

                    if (result != null)

                    {

                        foreach (string key in result.Properties.PropertyNames)

                        {

                            foreach (Object propValue in result.Properties[key])

                            {

                                value += key + " = " + propValue + "\r\n";

                                textBox1.Text += key + " = " + propValue + "\r\n";

                            }

                        }

                    }

                    else

                    {

                        MessageBox.Show("使用者不存在");

                    }

                }

                catch (Exception ex)

                {

                    MessageBox.Show(ex.Message);

                }

                finally

                {

                    Searcher.Dispose();

                    ldapConnection.Dispose();

                }   

            }
  • 相关阅读:
    Java进行AES/DES加密,C#对其进行解密
    【程序员的吃鸡大法】利用OCR文字识别+百度算法搜索,玩转冲顶大会、百万英雄、芝士超人等答题赢奖金游戏
    TWaver初学实战——炫动2D机房之连线篇
    TWaver初学实战——炫动2D机房之设备篇
    TWaver初学实战——炫动2D机房之机柜篇
    TWaver初学实战——基于HTML5的交互式地铁图
    TWaver3D入门探索——3D拓扑图之人在江湖
    TWaver3D入门探索——3D拓扑图之绽放的小球花
    TWaver初学实战——如何在TWaver属性表中添加日历控件?
    TWaver初学实战——如何在EasyUI中插入TWaver(续)
  • 原文地址:https://www.cnblogs.com/hishanghai/p/2611947.html
Copyright © 2020-2023  润新知