关于System.DirectoryServices.AccountManagement下,AccountExpirationDate不正确的问题

dotnba 2020-04-07 08:25:58
在System.DirectoryServices.AccountManagement下,使用AccountExpirationDate查找过期用户不正确。代码如下:

public List<UserPrincipal> GetUsersByExpiryDate(DateTime dtExpiryDate, MatchType enumMatchType = MatchType.LessThan)
{
List<UserPrincipal> userList = new List<UserPrincipal>();
using (UserPrincipal oUserPrincipal = new UserPrincipal(myPrincipalContext))
{
oUserPrincipal.AdvancedSearchFilter.AccountExpirationDate(dtExpiryDate, enumMatchType);
using (PrincipalSearcher oPrincipalSearcher = new PrincipalSearcher(oUserPrincipal))
{
using (PrincipalSearchResult<Principal> results = oPrincipalSearcher.FindAll())
{
foreach (UserPrincipal u in results)
{
userList.Add(u);
}
}
}
}
return userList;
}


具体而言:
1. 在AD中,一旦将某个用户置为过期状态,即便后面取消,采用本方法依旧认为该用户已经过期。
2.Administrator用户始终在过期用户中。
环境:
1. .net framework 4.8
2.AD安装在windows 2016 server上的
原因不明....

...全文
334 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
unioncron 2021-08-06
  • 打赏
  • 举报
回复

一样遇到坑,不知道咋搞

dotnba 2020-04-14
  • 打赏
  • 举报
回复
没人回答,自己顶下!
dotnba 2020-04-08
  • 打赏
  • 举报
回复
补充下,代码基本来自微软官方示例代码:https://docs.microsoft.com/zh-cn/previous-versions/bb384378(v=vs.90)

110,477

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧