我有一个程序可以对Active Directory中的对象运行一些验证,而我的检查之一就是查看是否在一年内设置了到期日期。使用一个UserPrincipal
对象,我可以检查.AccountExpirationDate
日期以查看是否有日期,但是我将如何查看该日期以查看它是否设置为在一年内到期?
这是我目前正在使用的
protected Check AccountExpiresMandatoryCheck = new Check()
{
ResultMessageTemplate = "User(s) don't have an expiry date or expiry date is greater than 1 year",
Run = delegate(Principal principal, AccountPoint point)
{
UserPrincipal user = principal as UserPrincipal;
if (user == null) return false;
return user.AccountExpirationDate != null || //check here if the date is a year or less;
}
};
我知道这样的东西一Check
和AccountPoint
的自定义对象我做的,但我希望这不会阻止任何人回答我的问题;
我如何检查到期日期是否设置为一年或更短
很难准确地说出您要做什么,但这可能会有所帮助。
DateTime oneYearAgoToday = DateTime.Today.AddYears(-1);
return user.AccountExpirationDate != null || user.AccountExpirationDate > oneYearAgoToday;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句