gpt4 book ai didi

active-directory - System.DirectoryServices 与 system.directoryservices.accountmanagement

转载 作者:行者123 更新时间:2023-12-04 08:32:46 25 4
gpt4 key购买 nike

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

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

谢谢。

最佳答案

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

查看此 C# 代码示例以了解用法:

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

关于active-directory - System.DirectoryServices 与 system.directoryservices.accountmanagement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1546871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com