首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >System.DirectoryServices vs system.directoryservices.accountmanagement

System.DirectoryServices vs system.directoryservices.accountmanagement
EN

Stack Overflow用户
提问于 2009-10-10 02:33:05
回答 2查看 6.8K关注 0票数 3

我有一个数组(propertyList),其中包含我要检索其数据的某些Active Directory属性的名称。使用Ironpython和.NET库System.DirectoryServices,我解决了以这种方式加载的属性的检索:

代码语言:javascript
复制
for propertyActDir in propertyList:
    obj.PropertiesToLoad.Add(propertyActDir)
res = obj.FindAll()
myDict = {}
for sr in res:
    for prop in propertyList:
        myDict[prop] = getField(prop,sr.Properties[prop][0])

函数getField是我的。如何使用库system.directoryservices.accountmanagement解决相同的情况?我认为这是不可能的。

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-10-10 05:39:15

是的,你是对的-- System.DirectoryServices.AccountManagement构建于System.DirectoryServices之上,并在.NET 3.5中引入。它使常见的Active Directory任务变得更容易。如果您需要任何特殊属性,则需要退回到System.DirectoryServices。

有关用法,请参阅此C#代码示例:

代码语言:javascript
复制
// Connect to the current domain using the credentials of the executing user:
PrincipalContext currentDomain = new PrincipalContext(ContextType.Domain);

// Search the entire domain for users with non-expiring passwords:
UserPrincipal userQuery = new UserPrincipal(currentDomain);
userQuery.PasswordNeverExpires = true;

PrincipalSearcher searchForUser = new PrincipalSearcher(userQuery);

foreach (UserPrincipal foundUser in searchForUser.FindAll())
{
    Console.WriteLine("DistinguishedName: " + foundUser.DistinguishedName);

    // To get the countryCode-attribute you need to get the underlying DirectoryEntry-object:
    DirectoryEntry foundUserDE = (DirectoryEntry)foundUser.GetUnderlyingObject();

    Console.WriteLine("Country Code: " + foundUserDE.Properties["countryCode"].Value);
}
票数 6
EN

Stack Overflow用户

发布于 2009-10-10 09:16:42

System.DirectoryServices.AccountManagement (卓越的MSDN article on it here)旨在帮助您更轻松地管理用户和组,例如

  • find users and groups
  • create users and groups
  • set specific properties on users and groups

它是而不是,旨在处理您所描述的“通用”属性管理-在这种情况下,只需继续使用System.DirectoryServices,没有什么可以阻止您这样做!

Marc

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1546871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档