我有一个数组(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解决相同的情况?我认为这是不可能的。
谢谢。
发布于 2009-10-10 05:39:15
是的,你是对的-- 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);
}发布于 2009-10-10 09:16:42
System.DirectoryServices.AccountManagement (卓越的MSDN article on it here)旨在帮助您更轻松地管理用户和组,例如
它是而不是,旨在处理您所描述的“通用”属性管理-在这种情况下,只需继续使用System.DirectoryServices,没有什么可以阻止您这样做!
Marc
https://stackoverflow.com/questions/1546871
复制相似问题