如何找到 LastLogonTimestamp 小于特定日期或为空的计算机
How can I find computers with LastLogonTimestamp less than a certain date OR null
以下代码returns 所有登录日期早于 3 个月前但未获取最后登录时间戳为空的计算机主体
PrincipalContext context = new PrincipalContext(ContextType.Domain);
PrincipalSearchResult<ComputerPrincipal> computers = ComputerPrincipal.FindByLogonTime(context, DateTime.Now.AddMonths(-3), MatchType.LessThanOrEquals);
我怎样才能优雅地添加到 "computers" 那些具有空值 "lastlogontimestamp" 值的值?
我放弃了 ComputerPrincipal.FindByLogonTime,因为它找不到 null 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)。
全新一期,但当前一期是"solved"
以下代码returns 所有登录日期早于 3 个月前但未获取最后登录时间戳为空的计算机主体
PrincipalContext context = new PrincipalContext(ContextType.Domain);
PrincipalSearchResult<ComputerPrincipal> computers = ComputerPrincipal.FindByLogonTime(context, DateTime.Now.AddMonths(-3), MatchType.LessThanOrEquals);
我怎样才能优雅地添加到 "computers" 那些具有空值 "lastlogontimestamp" 值的值?
我放弃了 ComputerPrincipal.FindByLogonTime,因为它找不到 null 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)。
全新一期,但当前一期是"solved"