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