c#查询从未登录过的用户的Active Directory
我需要识别Active Directory中的用户,这些用户在这么长时间后没有登录,或者从未登录过 我有基于登录日期进行查询的代码,但我一直在寻找从未登录过的用户 以下是我目前掌握的代码:c#查询从未登录过的用户的Active Directory,c#,active-directory,C#,Active Directory,我需要识别Active Directory中的用户,这些用户在这么长时间后没有登录,或者从未登录过 我有基于登录日期进行查询的代码,但我一直在寻找从未登录过的用户 以下是我目前掌握的代码: UserPrincipal userTmpl = new UserPrincipal(pc); if(prmLoginDate.HasValue) userTmpl.AdvancedSearchFilter.LastLogonTime(prmLoginDate.Value, MatchType.Les
UserPrincipal userTmpl = new UserPrincipal(pc);
if(prmLoginDate.HasValue)
userTmpl.AdvancedSearchFilter.LastLogonTime(prmLoginDate.Value, MatchType.LessThanOrEquals);
else
userTmpl.LastLogon = //This is where I would like to just say 'null' or something like that;
PrincipalSearcher srch = new PrincipalSearcher(userTmpl);
foreach (Principal p in srch.FindAll())
{
//... Do stuff here
}
非常感谢您提供有关如何执行此特定搜索的任何帮助。您是否尝试将DateTime.MinValue传递为prmLoginDate?我假设您意识到
LastLogon
是AD属性lastLogonTimestamp
,并且仅每14天复制一次(默认情况下),因此您不知道是否有人登录(这是第一次)在过去14天内。您必须单独查询每个域控制器的非复制lastLogon
属性,以确定真正的上次登录。