0

以下代码返回登录日期早于 3 个月前的所有计算机负责人,但没有获取 lastlogontimestamp 为 null 的所有计算机负责人

PrincipalContext context = new PrincipalContext(ContextType.Domain);
PrincipalSearchResult<ComputerPrincipal> computers = ComputerPrincipal.FindByLogonTime(context, DateTime.Now.AddMonths(-3), MatchType.LessThanOrEquals);

我怎样才能优雅地将那些具有空值“lastlogontimestamp”值的“计算机”添加到“计算机”中?

4

1 回答 1

1

我取消了 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)。

一个全新的问题,但当前的问题已“解决”

于 2019-05-23T20:47:56.353 回答