-
C#教程之C#教程之C#读取AD域用户信息
本站最新发布 C#从入门到精通
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
private const string domainName = "本机IP地址或域名" ; private const string adAdmin = "管理员帐号" ; private const string password = "管理员密码" ; private const string ouName = "子节点名" ; //只是一个子节点名 private DataTable GetADUsers() { DataTable dt = new DataTable(); dt.Columns.Add( "sAMAccountName" ); //帐号 dt.Columns.Add( "displayName" ); //显示名称 dt.Columns.Add( "description" ); //描述 dt.Columns.Add( "telephoneNumber" ); //电话号码 dt.Columns.Add( "mail" ); //邮箱地址 dt.Columns.Add( "wWWHomePage" ); //网页 dt.Columns.Add( "c" ); //国家 dt.Columns.Add( "st" ); //省/自治区 dt.Columns.Add( "l" ); //市/县 dt.Columns.Add( "streetAddress" ); //街道 dt.Columns.Add( "company" ); //公司 dt.Columns.Add( "department" ); //部门 dt.Columns.Add( "title" ); //职务 dt.Columns.Add( "manager" ); //我的经理 DirectoryEntry adRoot = new DirectoryEntry( "LDAP://" + domainName, adAdmin, password, AuthenticationTypes.Secure); DirectoryEntry ou = adRoot.Children.Find( "OU=" + ouName); DirectorySearcher mySearcher = new DirectorySearcher(ou); //想搜索出所有,此处可省参数 mySearcher.Filter = ( "(objectClass=user)" ); //user表示用户,group表示组 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) //{ // //获取用户所在的组织单位 // dr["OU"] = user.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; } |
栏目列表
最新更新
如何使用OS模块中的stat方法
Python os 模块
seek() 方法
python打开文件实例1
Python写入文件
什么是流?
文件操作如何进制逐行读取
Python相对路径
with创建临时运行环境
Python文件操作
.Net Standard(.Net Core)实现获取配置信息
Linux PXE + Kickstart 自动装机
Shell 编程 基础
Shell 编程 条件语句
CentOS8-网卡配置及详解
Linux中LVM逻辑卷管理
1.数码相框-相框框架分析(1)
Ubuntu armhf 版本国内源
Linux中raid磁盘阵列
搭建简易网站
access教程之Access简介
mysql 安装了最新版本8.x版本后的报错:
Mysql空间数据&空间索引(spatial)
如何远程连接SQL Server数据库的图文教程
复制SqlServer数据库的方法
搜索sql语句
sql中返回参数的值
sql中生成查询的模糊匹配字符串
数据定义功能
数据操作功能