从 AD 域中获取所有用户
- 作者: 那晚越女说我?
- 来源: 51数据库
- 2022-10-21
问题描述
我需要能够识别我的 AD (Active Directory) 域中的所有用户.我有域名,仅此而已.如果我可以将它作为 UserPrincipal 或其他东西的列表来获取它会很震撼,但如果它只是一个字符串,那么我可以从那里获取我需要的其余信息.
I have a need to be able to identify all of the users on my AD (Active Directory) domain. I have the domain name and that is about it. It would rock if i could get it as a list of UserPrincipal or something but if its just a string then i can get the rest of the info i need from there.
谢谢!
推荐答案
如果你只需要获取用户列表你可以使用这个代码 -
If you just have to get the users list you can use this code -
var dirEntry = new DirectoryEntry(string.Format("LDAP://{0}/{1}", "x.y.com", "DC=x,DC=y,DC=com"));
var searcher = new DirectorySearcher(dirEntry)
{
Filter = "(&(&(objectClass=user)(objectClass=person)))"
};
var resultCollection = searcher.FindAll();
但是,如果您需要对 AD 进行更多操作,则应考虑使用 LINQ to AD API http://linqtoad.codeplex.com/
However if you have to more operations with AD you should consider using LINQ to AD API http://linqtoad.codeplex.com/
它是一个基于 Linq 的 API,用于处理 AD.易于使用,我用它取得了一些不错的结果.
It is a Linq based API to work with AD. Easy to use and I have got some good results with it.
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
