Active directory System.DirectoryServices vs System.DirectoryServices.accountmanagement
我有一个数组(propertyList),其中包含我要检索其数据的某些Active Directory属性的名称。使用Ironpython和.NET library System.DirectoryServices,我可以通过以下方式解决要加载的属性检索问题:Active directory System.DirectoryServices vs System.DirectoryServices.accountmanagement,active-directory,Active Directory,我有一个数组(propertyList),其中包含我要检索其数据的某些Active Directory属性的名称。使用Ironpython和.NET library System.DirectoryServices,我可以通过以下方式解决要加载的属性检索问题: for propertyActDir in propertyList: obj.PropertiesToLoad.Add(propertyActDir) res = obj.FindAll() myDict = {} for sr
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函数是我的。如何使用library system.directoryservices.accountmanagement解决相同的问题?我认为这是不可能的
谢谢。是的,你说得对-System.DirectoryServices.AccountManagement构建在System.DirectoryServices的基础上,并随.NET 3.5一起引入。它使常见的Active Directory任务变得更容易。如果需要任何特殊属性,则需要返回System.DirectoryServices 有关用法,请参见此C#代码示例:
//使用执行用户的凭据连接到当前域:
PrincipalContext currentDomain=新PrincipalContext(ContextType.Domain);
//在整个域中搜索密码不过期的用户:
UserPrincipal userQuery=新的UserPrincipal(currentDomain);
userQuery.PasswordNeverExpires=true;
PrincipalSearchForUser=新PrincipalSearcher(用户查询);
foreach(searchForUser.FindAll()中的UserPrincipal foundUser)
{
Console.WriteLine(“DifferentizedName:+foundUser.DifferentizedName”);
//要获取countryCode属性,需要获取基础DirectoryEntry对象:
DirectoryEntry foundUserDE=(DirectoryEntry)foundUser.GetUnderlyingObject();
Console.WriteLine(“国家代码:“+foundUserDE.Properties[“countryCode”].Value”);
}
System.DirectoryServices.AccountManagement(优秀)旨在帮助您更轻松地管理用户和组,例如
- 查找用户和组
- 创建用户和组
- 设置用户和组的特定属性
系统即可。DirectoryServices
,没有任何东西可以阻止您这样做
马克谢谢你的例子。正如您所说,有必要回到System.DirectoryServices,但在本例中,扩展了目录对象类:UserPrincipal、GroupPrincipal和ComputerPrincipal,如中所示。