下面的代码返回所有具有3个月前登录日期但没有为lastlogontimestamp设置为null的计算机原理
PrincipalContext context = new PrincipalContext(ContextType.Domain);
PrincipalSearchResult<ComputerPrincipal> computers = ComputerPrincipal.FindByLogonTime(context, DateTime.Now.AddMonths(-3), MatchType.LessThanOrEquals);
如何优雅地将具有“ lastlogontimestamp”值的空值的计算机添加到“计算机”?
答案 0 :(得分:1)
我取消了ComputerPrincipal.FindByLogonTime,因为它找不到空的LogonTime,并使用了旧的经典工具DirectorySearcher
DirectorySearcher Computersearcher = new DirectorySearcher
{
SearchRoot = new DirectoryEntry(baseOU),
Filter = "(&(whenCreated<=" + WhenCreated + ")(!(userAccountControl=2))(|(lastLogonTimestamp<=" + DateInt + ")(lastLogonTimestamp=0))(objectClass=computer))",
SearchScope = SearchScope.Subtree,
PageSize = 1000,
Sort = new SortOption("Name", SortDirection.Ascending)
};
SearchResultCollection ComputerResults = Computersearcher.FindAll();
}
这具有一个不幸的副作用,即我曾经创建的可观察集合不再在WPF列表框中显示名称(尽管设置了DisplayNamePath)。
一个全新的问题,但当前已“解决”