我正在尝试使用C#访问AD用户的"msDS-ResultantPSO“属性值,我在用户上应用了密码策略,它显示了"msDS-ResultantPSO”attribute.Now中的值,我正在尝试使用C#以相同的方式获取此值,以获取AD用户的普通属性,如"FirstName,LastName,Email...".I将ResulantPSO属性与其他普通属性一起添加到load.My代码中,带来除"msDS-ResultantPSO“之外的所有正常属性值。
在这方面,请任何人能帮助我。
发布于 2016-07-21 06:15:03
我必须确保运行我的程序的用户具有适当的AD读取权限,而不是这样做会让您更接近:
var ad = new PrincipalContext(ContextType.Domain, _domain, _ldapPathOu);
UserPrincipal user = UserPrincipal.FindByIdentity(ad, username);
DirectoryEntry entry = user.GetUnderlyingObject() as DirectoryEntry;
DirectorySearcher mySearcher = new DirectorySearcher(entry);
SearchResultCollection results;
mySearcher.PropertiesToLoad.Add("msDS-ResultantPSO");
results = mySearcher.FindAll();
if (results.Count >= 1)
{
string pso = results[0].Properties["msDS-ResultantPSO"][0].ToString();
//do something with the pso..
DirectoryEntry d = new DirectoryEntry(@"LDAP://corp.example.com/"+ pso);
var searchForPassPolicy = new DirectorySearcher(d);
searchForPassPolicy.Filter = @"(objectClass=msDS-PasswordSettings)";
searchForPassPolicy.SearchScope = System.DirectoryServices.SearchScope.Subtree;
searchForPassPolicy.PropertiesToLoad.AddRange(new string[] {"msDS-MaximumPasswordAge"});
var x = searchForPassPolicy.FindAll();
var maxAge = (Int64)x[0].Properties["msDS-MaximumPasswordAge"][0];
var maxPwdAgeInDays = ConvertTimeToDays(maxAge);
}https://stackoverflow.com/questions/38177494
复制相似问题