C#DirectoryEntry找到具有特定属性的所有用户(wwwhomepage)
C#中使用Directory输入的最佳方法是找到所有属性wwwhomepage的用户。
我能够查看特定用户是否拥有它,但我尚未使用目录条目来搜索所有用户以搜索所有用户。
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, myDomain, Login.authUserName, Login.authPassword);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, username);
if (user != null) {
DirectoryEntry de = (user.GetUnderlyingObject() as DirectoryEntry);
if (de != null) {
string whatIWant = de.Properties["wWWHomePage"].Value.ToString();
}
}
What would be the best way in C# to use directory entry to find all users with the attribute wWWHomePage filled in.
I am able to see if a specific user has it but I have not used Directory Entry to search all users for something like this.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, myDomain, Login.authUserName, Login.authPassword);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, username);
if (user != null) {
DirectoryEntry de = (user.GetUnderlyingObject() as DirectoryEntry);
if (de != null) {
string whatIWant = de.Properties["wWWHomePage"].Value.ToString();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
DirectoryEntry
与DirectorySearcher
并指定搜索过滤器
以获取所需的东西。过滤器
您想要的模板是:其中
property_name
是您要搜索的属性,而search_term
是值。您可以将*
用作通配符搜索,它将为您提供具有此属性的所有对象。这是一个快速示例:
use
DirectoryEntry
withDirectorySearcher
and specify the searchFilter
to get what you want.the
Filter
template you want is :where
PROPERTY_NAME
is the property you want to search in, andSEARCH_TERM
is the value. you could use the*
as a wildcard search, it would give you all objects that has this property.here is a quick example :