简体   繁体   English

如何获得Active Directory中文件夹的用户?

[英]How I get the users of a folder in Active Directory?

hi I want to build a LDAP Query how I get all User in a under folder... For example: 嗨,我想建立一个LDAP查询,我如何将所有用户放在一个文件夹中...例如:

OU=DBG,OU=THINCLIENT,OU=NPS,OU=services,DC=YourDomain,DC=com

I want to get all Users ins this folder from the Active Directory. 我想从Active Directory中将所有用户ins放在此文件夹中。 For this I have a Query but I don't know how I get the users of this Folder :( 为此,我有一个查询,但不知道如何获取此文件夹的用户:(

(&(objectClass=user)(objectCategory=user)(??????))

If you're using .NET 3.5 or newer, you can use a PrincipalSearcher and a "query-by-example" principal to do your searching: 如果使用的是.NET 3.5或更高版本,则可以使用PrincipalSearcher和“按示例查询”主体进行搜索:

// create your domain context
string container = "OU=DBG,OU=THINCLIENT,OU=NPS,OU=services,DC=YourDomain,DC=com";
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YourDomain", container))
{
   // define a "query-by-example" principal - here, we search for UserPrincipal 
   UserPrincipal qbeUser = new UserPrincipal(ctx);

   // create your principal searcher passing in the QBE principal    
   PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

   // find all matches
   foreach(var found in srch.FindAll())
   {
       // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
   }
}

If you haven't already - absolutely read the MSDN article Managing Directory Security Principals in the .NET Framework 3.5 which shows nicely how to make the best use of the new features in System.DirectoryServices.AccountManagement . 如果您还没有-一定要阅读MSDN文章.NET Framework 3.5中的管理目录安全性主体”,它很好地展示了如何充分利用System.DirectoryServices.AccountManagement中的新功能。 Or see the MSDN documentation on the System.DirectoryServices.AccountManagement namespace. 或参阅System.DirectoryServices.AccountManagement命名空间MSDN文档

You'll need to add a reference to the System.DirectoryServices.AccountManagement assembly in your references, and you'll need a line like this: 您需要在引用中添加对System.DirectoryServices.AccountManagement程序集的引用,并且需要这样的一行:

using System.DirectoryServices.AccountManagement;

at the top of your code-behind file for this to work. 在您的代码隐藏文件的顶部,以使其正常工作。

You can specify any of the properties on the UserPrincipal and use those as "query-by-example" for your PrincipalSearcher . 您可以在UserPrincipal上指定任何属性,并将它们用作PrincipalSearcher “按示例查询”。

You can use System.DirectoryServices Namespace. 您可以使用System.DirectoryServices命名空间。

 DirectoryEntry scope = new   DirectoryEntry("LDAP://OU=DBG,OU=THINCLIENT,OU=NPS,OU=services,DC=YourDomain,DC=com");

 string filter = "(&(objectClass=user)(objectCategory=user))";
 string[] attrs = new string[]{"samaccountname","whencreated"};
 DirectorySearcher searcher = new  DirectorySearcher(scope,filter,attrs);

 foreach(SearchResult result in searcher.FindAll())
 {
     //result.Properties["attribute"][0].ToString();
 }

尝试

(&(objectClass=user)(objectCategory=user)(homeDirectory=*YourFolderName*))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为活动目录的用户授予FTP文件夹权限 - How can I grant permissions for a FTP Folder for users of the active directory 如何从活动目录中获取用户列表? - How can I get a list of users from active directory? 如何从Active Directory中获取用户头像? - How to get users avatar from Active Directory? 如何获取Active Directory用户列表(仅Windows登录屏幕中显示的用户) - How can I get a list of Active Directory Users (Only the Users that appear in the windows Logon Screen) 获取组中的Active Directory用户 - Get Active Directory users in Group 使用户进入Azure活动目录 - To get users in azure active directory 提取指定文件夹中活动目录中的所有用户 - Fetch all users in active directory in a specified folder 如何获得所有Active Directory用户的用户名和显示名称 - How can I get all Active Directory Users username and display name C# - 如何从 Active Directory 获取用户的“网页”属性? - C# - How do I Get a users "Web Page" property from Active Directory? 如何使Active Directory文件夹中的用户可以在ASP.NEt应用程序中看到Web窗体? - How I can make that users from a Active Directory Folder can see a webform in my ASP.NEt Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM