System.DirectoryServices中VS system.directoryservices.accountmanagement [英] System.DirectoryServices vs system.directoryservices.accountmanagement

查看:161
本文介绍了System.DirectoryServices中VS system.directoryservices.accountmanagement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组(propertyList),其中包含一定的Active Directory属性我想要检索其数据的名称。使用IronPython和NET库System.DirectoryServices中予解决属性的检​​索以这种方式被装载

I have an array (propertyList) that contains the names of certain Active Directory properties whose data I want to retrieve. Using Ironpython and .NET library System.DirectoryServices I solve the retrieval of properties to be loaded in this way:

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同样的情况?我认为这是不可能的。

The function getField is mine. How can I solve the same situation using the library system.directoryservices.accountmanagement? I think it is not possible.

感谢。

推荐答案

是的,你说得对 - System.DirectoryServices.AccountManagement基础上System.DirectoryServices中,并引入.NET 3.5。它使普通的Active Directory任务变得更加容易。如果您需要任何特殊的属性,你需要回落到System.DirectoryServices中。

Yes, you're right - System.DirectoryServices.AccountManagement builds on System.DirectoryServices and was introduced with .NET 3.5. It makes common Active Directory tasks easier. If you need any special properties you need to fall back to System.DirectoryServices.

请参阅使用此C#code样品:<​​/ P>

See this C# code sample for usage:

// 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);
}

这篇关于System.DirectoryServices中VS system.directoryservices.accountmanagement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆