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的更多相关文章

  1. 【Azure API 管理】解决API Management添加AAD Group时遇见的 Failed to query Azure Active Directory graph due to error 错误

    问题描述 为APIM添加AAD Group时候,等待很长很长的时间,结果添加失败.错误消息为: Write Groups ValidationError :Failed to query Azure ...

  2. SharePoint 2103 Check user permission on list

    一.需求: check user 对SharePoint list 的permission 代码如下: private static string GetListPermission(SPList l ...

  3. Integrating SharePoint 2013 with ADFS and Shibboleth

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

  4. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q69-Q71)

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

  5. 通过SEP禁用USB

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

  6. SharePoint 2013 Nintex Workflow 工作流帮助(十三)

    博客地址 http://blog.csdn.net/foxdave 工作流动作 35. Delegate Workflow Task(User interaction分组) 该操作将委托未处理的工作流 ...

  7. SharePoint 2013 Nintex Workflow 工作流帮助(九)

    博客地址 http://blog.csdn.net/foxdave 前叙:假期结束了,知道为什么假期如此短暂吗?因为假期的每天只有半天.春节过完了,新的一年开始了,大家或许之前在新年的时候都许下了自己 ...

  8. SharePoint 2013 Nintex Workflow 工作流帮助(二)

    博客地址 http://blog.csdn.net/foxdave 工作流动作 1. Action Set(Logic and flow分组) 它是一个工作流的集合,可以理解为容器的东西.所以它本身并 ...

  9. SharePoint Security and Permission System Overview

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

随机推荐

  1. ListOrderedMap

    要有序能够用List,要便于查找能够用Map,那既要有序又便于查找呢? 近期我就遇到了这样一个问题.Java没有给我们提供现成的类.我们全然能够自己开发个类继承List和Map(Java原来就有不能够 ...

  2. Oracle用户及角色的权限管理[Oracle基础]

    1.查看全部用户:   select * from dba_users;   select * from all_users;   select * from user_users; 2.查看用户或角 ...

  3. JS字符处理

    JS取整 1.toFixed(num)(ps:num为保留小数点后几位) 自定义保留小数点后几位,进行四舍五入.严格来说,这个函数不属于取整,但是当num=0时,也就是取整了,所以一起放到这里,方便查 ...

  4. Linux开发环境搭建与使用——ubuntu更新设置

    ubuntu操作系统公布时,为了减小操作系统的体积,只配备了主要的系统软件.应用软件.我们开发中须要用到的大部分软件都须要在使用中从网上自行更新. 假设ubuntu没有网络,能够说寸步难行. 以下教大 ...

  5. Liunx下Tomcat+MYSQL+Nginx配置

    环境:centos6.4 min #安装编译库及依赖模块 yum -y install gcc gcc-c++ autoconf automake make yum -y install zlib z ...

  6. pip和easy_install使用方式

    easy_install 跟 pip 都是 Python 的套件管理程式,有了它們,在使用 Python 開發程式的時候會帶來不少方便. easy_install 和 pip 有什麼不一樣?據 pip ...

  7. [原创]oracle 顺序号生成函数。仿Sequence

    问题提出自项目中的老代码:一个Bill表,存储所有的表单信息,比如:员工入职单,离职单等等.(别喷,我知道要分多个表.但领导的意愿你是没办法违背的)表单的单据号是以四个字母+年月日+数字顺序号来表示. ...

  8. [Effective C++ --006]若不能使用编译器自动生成的函数,就该明确拒绝

    ■本文内容■□第一节 <引言> 在条款五的讲解中,我们已经知道编译器是聪明的家伙,它会帮助你生成类的构造函数.析构函数.一个copy构造函数和一个赋值运算符.有时真的要感谢编译器所做的这一 ...

  9. C#_StringBuilder分离字符串实例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Stri ...

  10. C++之类的析构函数

    一.认识析构函数 在我的前一篇博客介绍了类的构造函数.http://www.cnblogs.com/MrListening/p/5557114.html. 这里我们来简单说说类的析构函数,它是类的一个 ...