C # Read AD domain user information

Source: Internet
Author: User
Tags administrator password samaccountname

Tag:get   uname   csharp    number    ble    ada    read    name   res   

        Private Const string domainName = "Native IP address or domain name";        Private Const string adadmin = "Administrator Account";        Private Const string Password = "Administrator Password"; Private Const string ouname = "Child node name";//Just a sub-node name private DataTable Getadusers () {datatable dt = new Data            Table (); Dt. Columns.Add ("sAMAccountName");//Account dt. Columns.Add ("DisplayName");//display name DT. Columns.Add ("description");//Description dt. Columns.Add ("telephonenumber");//telephone number dt. Columns.Add ("Mail"); e-mail address dt. Columns.Add ("Wwwhomepage"); Web page dt. Columns.Add ("C"); Country dt. Columns.Add ("St"); State/Province dt. Columns.Add ("L"); City/County dt. Columns.Add ("streetaddress"); Street dt. Columns.Add ("Company");//Corporation DT. Columns.Add ("department");//Department dt. Columns.Add ("title");//Position dt. Columns.Add ("manager");//My manager DirectoryEntry Adroot = new DirectoryEntry ("LDAP://" + domainName, Adadmin, passWord, authenticationtypes.secure);            DirectoryEntry OU = AdRoot.Children.Find ("ou=" + ouname); DirectorySearcher mysearcher = new DirectorySearcher (OU);//want to search out all, here can save parameter Mysearcher.filter = ("(Objectclass=use R) ");                 User, group represents a set of foreach (System.DirectoryServices.SearchResult resEnt in Mysearcher.findall ()) { if (user. Properties.contains ("Mail"))//{//dr["mail"] = user. properties["Mail"][0].                ToString (); }//if (user. Parent.name! = string. Empty && user. Parent.Name.IndexOf (' = ') >-1)//{////Get the organizational unit where the user is located//dr["OU"] = us Er.                Parent.Name.Split (' = ') [1]; } DataRow dr = dt.                NewRow ();                DirectoryEntry user = Resent.getdirectoryentry (); if (user. Properties.contains ("sAMAccountName")) {dr["sAMAccountName"] = User. properties["sAMAccountName"][0].                ToString (); } if (user. Properties.contains ("DisplayName")) {dr["displayName"] = user. properties["DisplayName"][0].                ToString (); } if (user. Properties.contains ("description")) {dr["description"] = user. properties["description"][0].                ToString (); } if (user. Properties.contains ("telephonenumber")) {dr["telephonenumber"] = user. properties["Telephonenumber"][0].                ToString (); } if (user. Properties.contains ("Mail")) {dr["mail"] = user. properties["Mail"][0].                ToString (); } if (user. Properties.contains ("Wwwhomepage")) {dr["wwwhomepage"] = user. properties["Wwwhomepage"][0].                ToString (); } if (user. Properties.contains ("C") {dr["c"] = user. properties["C"][0].                ToString (); } if (user. Properties.contains ("St")) {dr["st"] = user. properties["St"][0].                ToString (); } if (user. Properties.contains ("L")) {dr["L"] = user. properties["L"][0].                ToString (); } if (user. Properties.contains ("streetaddress")) {dr["streetaddress"] = user. properties["StreetAddress"][0].                ToString (); } if (user. Properties.contains ("Company")) {dr["Company"] = user. Properties["Company"][0].                ToString (); } if (user. Properties.contains ("department")) {dr["department"] = user. properties["department"][0].                ToString (); } if (user.                Properties.contains ("title")){dr["title"] = user. properties["title"][0].                ToString (); } if (user. Properties.contains ("manager")) {dr["manager"] = user. properties["Manager"][0]. ToString (). Split (', ') [0].                Remove (0, 3); } dt.            Rows.Add (DR);        } return DT; }

  

C # Read AD domain user information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.