AD,Group
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的更多相关文章
- 【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 ...
- SharePoint 2103 Check user permission on list
一.需求: check user 对SharePoint list 的permission 代码如下: private static string GetListPermission(SPList l ...
- Integrating SharePoint 2013 with ADFS and Shibboleth
Time again to attempt to implement that exciting technology, Federation Services (Web Single Sign On ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q69-Q71)
Question 69 You are designing an extranet site using SharePoint 2010. This site must allow employees ...
- 通过SEP禁用USB
1 Introduction 1.1 Scope This document provides comprehensive information of the reinforce ...
- SharePoint 2013 Nintex Workflow 工作流帮助(十三)
博客地址 http://blog.csdn.net/foxdave 工作流动作 35. Delegate Workflow Task(User interaction分组) 该操作将委托未处理的工作流 ...
- SharePoint 2013 Nintex Workflow 工作流帮助(九)
博客地址 http://blog.csdn.net/foxdave 前叙:假期结束了,知道为什么假期如此短暂吗?因为假期的每天只有半天.春节过完了,新的一年开始了,大家或许之前在新年的时候都许下了自己 ...
- SharePoint 2013 Nintex Workflow 工作流帮助(二)
博客地址 http://blog.csdn.net/foxdave 工作流动作 1. Action Set(Logic and flow分组) 它是一个工作流的集合,可以理解为容器的东西.所以它本身并 ...
- SharePoint Security and Permission System Overview
转:http://www.sharepointblues.com/2010/09/01/sharepoint-security-and-permission-system-overview/ Shar ...
随机推荐
- 创建性能监视器(logman)
在本地计算机上抓取性能信息 Logman.exe create counter Perf-1Second -f bincirc -max 500 -c "\Processor(*)\% Pr ...
- [ExtJS5学习笔记]第十节 Extjs5新增特性之ViewModel和DataBinding
本文地址:http://blog.csdn.net/sushengmiyan/article/details/38612721 本文作者:sushengmiyan ------------------ ...
- jQuery操作select option
jQuery获取Select选择的Text和Value: 1. var checkText=jQuery("#select_id").find("option:selec ...
- IE下载打印文件的时候,下载打印闪一下就没有了
这是因为我们的浏览器没有将文件下载的自动提示设为启用.点击IE菜单栏中的“工具”—“Internet选项”-安全—可信站点—自定义级别 1,添加信任站点 打开IE浏览器,输入需要下载文件的地址 选择[ ...
- ORM之三:DbProvider与DbFactory
这里涉及到两个关键对象,一个是DbProvider,另一个就是DbFactory.粗略草图如下: 从上图可以看出,开放给消费者的接口就是DbProvider类,不过他主要继承IDbProvider ...
- android学习日记03--常用控件checkbox/radiobutton
常用控件3.checkbox 复选框,确定是否勾选,点击一下勾选,点击第二下取消,当有一系列备选项时适合用checkbox控件,方便用户提交数据. 贴上例子Activity的java代码 packag ...
- careercup-C和C++ 13.5
13.5 谈谈C语言关键字”volatile”的意义(或重要性)? 解答 关键字volatile的作用是指示编译器,即使代码不对变量做任何改动,该变量的值仍可能被外界修改.操作系统.硬件或其他线程都可 ...
- 微软雅黑字体IE6 opacity改变,字体会变样子
微软雅黑字体IE6 opacity改变,字体会变样子,换个字体就好了
- 【转】int const A::func()和int A::func() const
int const A::func() { return 0; }int A::func() const { return 0; } 上面的代码是合法的,其中A::func成员函数[只能在成员函数后面 ...
- iOS-制作Framework
步骤 打开Xcode,创建新工程.手下留情,请先看图! 在TARGETS下选中工程,在Build Settings下更改几个参数. 更改参数 在Architectures下增加armv7s,并选中.将 ...