カスタム属性lastLogonTime
構文を追加しました: UTC Coded Time
. クラスを拡張UserPrincipal
して、そのカスタム属性を GET/SET しました。
...
[DirectoryProperty("lastLogonTime")]
public DateTime? LastLogonTime
{
get
{
object[] result = this.ExtensionGet("lastLogonTime");
if (result != null && result.Count() > 0) return (DateTime?)result[0];
return null;
}
set
{
this.ExtensionSet("lastLogonTime", value);
}
}
...
AdvancedFilters
また、このカスタム属性で検索できるように拡張しました。
MyUserPrincipalSearch searchFilter;
new public MyUserPrincipalSearch AdvancedSearchFilter
{
get
{
if (null == searchFilter)
searchFilter = new MyUserPrincipalSearch(this);
return searchFilter;
}
}
public class MyUserPrincipalSearch: AdvancedFilters
{
public MyUserPrincipalSearch(Principal p) : base(p) { }
public void LastLogonTime (DateTime? lastLogonTime, MatchType mt)
{
this.AdvancedFilterSet("lastLogonTime", lastLogonTime.Value, typeof(DateTime?), mt);
}
}
lastLogonTime
ここで、所有者が未満の すべてのユーザーを検索したいと思いますday
。
using (PrincipalContext ctx = ADLDSUtility.Users)
{
MyUserPrincipal filter = new MyUserPrincipal(ctx);
filter.AdvancedSearchFilter.LastLogonTime((DateTime.Now - new TimeSpan(1,0,0,0,0)), MatchType.LessThan);
PrincipalSearcher ps = new PrincipalSearcher(filter);
foreach (MyUserPrincipal p in ps.FindAll())
{
//my custom code
}
}
上記の検索で結果が返されません。過去数日間ログインしていないテスト ユーザーがいます。
、を試しましMatchType.GreaterThan
たMatchType.Equals
。それらのどれも結果を返していませんが、それらの基準に一致するユーザーがいます.
機能する唯一のフィルターは
filter.AdvancedSearchFilter.LastLogonTime(DateTime.Now , MatchType.NotEquals);
しかし、これは基本的にすべてのユーザーを返しています。検索結果が結果を返さない理由はありますか?
私の目標は、最終ログオン時間が日未満のすべてのユーザーを検索することですX
。
それらのユーザーを獲得する限り、私は他のソリューションに対してオープンです。
PS私はこれを回避する方法を知っています。すべてのユーザーをループし、それらlastLogonTime
を取得してから比較しますが、それは私がやっていることのやり過ぎです。