DataTable dtUser = GetEmptyDT();

            Dictionary<DirectoryEntry, string> test1 = GetUserAndGroup(clsConst.enumADName.AD_1);

            foreach (DirectoryEntry deUser in test1.Keys)
{
string groupname = test1[deUser];
string sAMAccountName = GetProperty(deUser, "sAMAccountName");
string mail = GetProperty(deUser, "mail");
string department = GetProperty(deUser, "Department");
string displayName = GetProperty(deUser, "displayName");
string givenName = GetProperty(deUser, "givenName");
string sn = GetProperty(deUser, "sn"); DataRow dr = dtUser.NewRow();
dr["ADName"] = clsConst.enumADName.AD_1;
dr["GroupName"] = groupname;
dr["LoginName"] = sAMAccountName;
dr["Department"] = department;
dr["MailAddress"] = mail;
dr["DisplayName"] = displayName;
dr["FirstName"] = givenName;
dr["LastName"] = sn;
dtUser.Rows.Add(dr);
} ExportLog(dtUser, "UserInformation_log", ConfigurationManager.AppSettings["UserInformationPath"]); public static Dictionary<DirectoryEntry, string> GetUserAndGroup(string ADName)
{
string[] GroupName = { string.Empty };
string path = string.Empty;
string username = string.Empty;
string password = string.Empty;
if (ADName.Equals(clsConst.enumADName.AD_1))
{
path = ConfigurationManager.AppSettings["1Path"];
username = ConfigurationManager.AppSettings["1UserName"];
password = ConfigurationManager.AppSettings["1Password"];
GroupName = ConfigurationManager.AppSettings["1Groups"].Split(',');
}
if (ADName.Equals(clsConst.enumADName.AD_2))
{
path = ConfigurationManager.AppSettings["2Path"];
username = ConfigurationManager.AppSettings["2UserName"];
password = ConfigurationManager.AppSettings["2Password"];
GroupName = ConfigurationManager.AppSettings["2Groups"].Split(',');
}
if (ADName.Equals(clsConst.enumADName.AD_3))
{
path = ConfigurationManager.AppSettings["3Path"];
username = ConfigurationManager.AppSettings["3UserName"];
password = ConfigurationManager.AppSettings["3Password"];
GroupName = ConfigurationManager.AppSettings["3Groups"].Split(',');
} List<SearchResult> results = new List<SearchResult>();
DirectoryEntry de = GetDirectoryObject(ADName); DirectorySearcher deSearch = new DirectorySearcher(); deSearch.SearchRoot = de;
string strFilter = string.Empty;
if (GroupName.Length <= )
{
return null;
}
strFilter = "(&(objectClass=group){0}(cn=" + GroupName[] + "){1})";
string s1 = string.Empty;
string s2 = string.Empty;
if (GroupName.Length > )
{
s1 = "(|";
for (int i = ; i < GroupName.Length; i++)
{
s2 += "(cn=" + GroupName[i] + ")";
}
s2 += ")";
}
strFilter = string.Format(strFilter, s1, s2); deSearch.Filter = strFilter;
deSearch.SearchScope = SearchScope.Subtree;
SearchResultCollection searchResults = deSearch.FindAll(); Dictionary<DirectoryEntry, string> groupAndUser = new Dictionary<DirectoryEntry, string>(); List<string> dnstr = new List<string>();
foreach (SearchResult searchResult in searchResults)
{ DirectoryEntry deGroup = new DirectoryEntry(searchResult.Path, username, password, AuthenticationTypes.Secure);
System.DirectoryServices.PropertyCollection pcoll = deGroup.Properties;
int n = pcoll["member"].Count; for (int l = ; l < n; l++)
{
DirectoryEntry deUser = new DirectoryEntry(path + "/" + pcoll["member"][l].ToString(), username, password, AuthenticationTypes.Secure);
string dn = deUser.Properties["distinguishedName"][].ToString();
if (!dnstr.Contains(dn))
{
dnstr.Add(dn);
groupAndUser.Add(deUser,deGroup.Name.Remove(,));
}
} }
return groupAndUser;
}

AD,Group More articles about

  1. SharePoint 2103 Check user permission on list

    One . demand : check user Yes SharePoint list Of permission The code is as follows : private static string GetListPermission(SPList l ...

  2. Integrating SharePoint 2013 with ADFS and Shibboleth

    Time again to attempt to implement that exciting technology, Federation Services (Web Single Sign On ...

  3. Sharepoint Learning notes — Exercise series --70-576 Problem solving -(Q69-Q71)

    Question 69 You are designing an extranet site using SharePoint 2010. This site must allow employees ...

  4. adopt SEP Ban USB

    1      Introduction 1.1      Scope This document provides comprehensive information of the reinforce ...

  5. SharePoint 2013 Nintex Workflow Workflow help ( 13、 ... and )

    Blog address http://blog.csdn.net/foxdave Workflow actions 35. Delegate Workflow Task(User interaction grouping ) This will delegate the unprocessed workflow ...

  6. SharePoint 2013 Nintex Workflow Workflow help ( Nine )

    Blog address  http://blog.csdn.net/foxdave Foreword : The holiday is over , Do you know why holidays are so short ? Because the holiday is only half a day . Spring Festival is over , A New Year has begun , You may have promised yourself in the new year ...

  7. SharePoint 2013 Nintex Workflow Workflow help ( Two )

    Blog address http://blog.csdn.net/foxdave Workflow actions 1. Action Set(Logic and flow grouping ) It's a collection of workflows , Something that can be understood as a container . So it's not in itself ...

  8. SharePoint Security and Permission System Overview

    turn :http://www.sharepointblues.com/2010/09/01/sharepoint-security-and-permission-system-overview/ Shar ...

  9. [ turn ]SharePoint 2010/2013 Use Javascript Three ways to determine authority

    This article tells SharePoint 2010/2013 Use Javascript To determine the implementation of the three methods of authority and its advantages and disadvantages . 1. According to the user's location SharePoint Group ( Let's say the user Leader Group can use ...

Random recommendation

  1. startService() and bindService() difference

    1. Life cycle :startService() Mode start ,Service It's through acceptance Intent And will experience onCreate() and onStart(). When a user issues an intent to destroy it, he experiences onDestroy(), and ...

  2. Luogu P1373 Small a and uim The great escape

    P1373 Small a and uim The great escape Subject provider lzn label Dynamic programming Original by Luo Gu difficulty Improve +/ Provincial election - Background Small a and uim Explore the rainforest . Suddenly a north wind came , A cloud surged in from the northern skyline , With lightning ...

  3. Palindrome (manacher)

    bare manacher I wrote that I knelt down ………… A place ( even numbers ) I didn't write it clearly …… I OOXOXOXOXXOXO #include<cstdio> #include<cstdlib> #i ...

  4. LVS-DR Pattern ( A detailed explanation of the schematic diagram )

    label ( The blank space to separate ): linux The author Q:972581034 Communication group :605799367. If you have any questions, please contact me or Jiaqun Preface LVS There are four working modes . among ,DR Pattern is one of the common patterns , The configuration is troublesome , here ...

  5. ubuntu Next ,python2.7 install mysqlldb Driving method

    Installation dependency : sudo apt-get install libmysqlclient-dev libmysqld-dev python-dev python-setuptools install MySQLdb p ...

  6. windows Next nginx Profile path

    nginx stay windowns Down the road http{ # Virtual host 1 server{ listen 80; # Listening port , be based on IP Change here when configuring , such as 192.168.1.100:8080; server_n ...

  7. luogu 2569 Stock Exchange A monotonous queue dp

    Notice the transfer equation branch 1. Buy out of thin air 2. Don't buy, don't sell 3. Buy on the original basis 4. Sell on the original basis Four situations head=1,tail=0; Judge again head<=tail It's fine too #include<bits/s ...

  8. h5 Call up the camera, scan the QR code and analyze

    2016 year 6 month 29 Daily supplement : Recently, I have done some form related projects , Used h5 Of input Control , There are many pits in the process of using . It also includes... Related to this article . First of all, we should know how to use h5 Newly provided properties getUserMedia ...

  9. Common character sets &amp; The code problem

    Character set Common character set classification ASCII And its extended character set effect : Predicative English and Western European languages . digit :ASCII Yes, it is 7 Bit means , Can express 128 Characters : Its extension uses 8 Who said , Express 256 Characters . Range :ASCII from 00 To 7F, ...

  10. Java bean Note the use of Boolean types in

    JavaBean It's a standard , Follow the standard Bean It's a system with attributes and getters/setters Methodical Java class . JavaBean The definition of is very simple , But there are still some things to pay attention to , for example Bean contains boolea ...