的pwdLastSet显示了在一台服务器,但不是在服务器B,即使它的存在 [英] pwdLastSet showing up on one server A but not on server B, even though it's there
问题描述
的pwdLastSet B中的用户由众人我是通过LDAP猜测创建未返回,我下面的code服务器B.在服务器。我可以看到现场,当我检查AD管理器的用户,但是当我试图通过code得到的pwdLastSet服务器B这是行不通的。然而,它在服务器A上,我透过AD创建用户的所有作品。
我也曾尝试LastPasswordSet通过UserPrincipal对象。
私有静态的DateTime DateTest(用户名字符串)
{
的userName = userName.Trim();
日期时间砍死;
使用(DirectorySearcher从DS =新DirectorySearcher从())
{
ds.SearchScope = SearchScope.Subtree;
ds.PropertiesToLoad.Add(的distinguishedName);
ds.PropertiesToLoad.Add(录pwdLastSet);
ds.PageSize = 1;
ds.ServerPageTimeLimit = TimeSpan.FromSeconds(2);
ds.Filter =的String.Format((及(objectCategory属性=用户)(sAMAccountName赋= {0})),用户名);
信息搜索结果SR = ds.FindOne();
//砍死= DateTime.FromFileTime((长)sr.Properties [的pwdLastSet] [0]);
IDictionaryEnumerator E = sr.Properties.GetEnumerator();
而(e.MoveNext())
{
//如果(typeof运算(ResultPropertyCollection)== e.Key.GetType())
// {
//的foreach(在VAR项目(ResultPropertyCollection)e.Key)
// {
// Console.WriteLine(E);
//}
//}
Console.Write(e.Key);
Console.Write(:);
的foreach(在VAR项目(ResultPropertyValueCollection)e.Value)
{
Console.WriteLine(项目);
}
}
}
返回DateTime.Now;
}
尽管我登录了企业/域管理员组成员身份的事实,这是当我执行它仍然没有工作。
然而,当我右键点击控制台应用程序并运行它以管理员身份,它的工作就像一个魅力。加尔!
pwdLastSet is not being returned in my code below on server B. On Server B the users are created by "Crowd" i'm guessing via LDAP. I can see the field when I examine the user in AD Manger, but when I try to get pwdLastSet on Server B through code it doesn't work. However it all works on server A where I create the users through AD.
I have also tried "LastPasswordSet" through the UserPrincipal object.
private static DateTime DateTest(string userName)
{
userName = userName.Trim();
DateTime hacked;
using (DirectorySearcher ds = new DirectorySearcher())
{
ds.SearchScope = SearchScope.Subtree;
ds.PropertiesToLoad.Add("distinguishedName");
ds.PropertiesToLoad.Add("pwdLastSet");
ds.PageSize = 1;
ds.ServerPageTimeLimit = TimeSpan.FromSeconds(2);
ds.Filter = string.Format("(&(objectCategory=user)(sAMAccountName={0}))", userName);
SearchResult sr = ds.FindOne();
//hacked = DateTime.FromFileTime((long)sr.Properties["pwdLastSet"][0]);
IDictionaryEnumerator e = sr.Properties.GetEnumerator();
while (e.MoveNext())
{
//if (typeof(ResultPropertyCollection) == e.Key.GetType())
//{
// foreach (var item in (ResultPropertyCollection)e.Key)
// {
// Console.WriteLine(e);
// }
//}
Console.Write(e.Key);
Console.Write(" : ");
foreach (var item in (ResultPropertyValueCollection)e.Value)
{
Console.WriteLine(item);
}
}
}
return DateTime.Now;
}
Despite the fact that my login has enterprise/domain admin group membership this was still not working when I executed it.
However when I right clicked the console app and ran it as administrator, it worked like a charm. Garr!
这篇关于的pwdLastSet显示了在一台服务器,但不是在服务器B,即使它的存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!