我对使用UserPrincipal
类(C#)是陌生的,因为我需要帮助来更正此问题以从Active Directory中为特定用户获取某些属性,因此我陷入困境。
private void AD_GetInfo()
{
DateTime sDT = DateTime.Today;
PrincipalContext sPContext = new PrincipalContext(ContextType.Domain, "CONTOSA");
UserPrincipal sUsrPrincipal = new UserPrincipal(sPContext);
sUsrPrincipal.AdvancedSearchFilter.(sDT, MatchType.Equals(myUserName).ToString);
PrincipalSearcher sPSearcher = new PrincipalSearcher(sUsrPrincipal);
UserPrincipal sResult = (UserPrincipal)sPSearcher.FindOne();
if (sResult != null)
{
textbox.text("Display Name " + sResult.DisplayName + "");
textbox.text("Email Address " + sResult.EmailAddress + "");
textbox.text("Telephone Number " + sResult.VoiceTelephoneNumber + "");
textbox.text("Account is Active " + sResult.Enabled + "");
textbox.text("Account Expiration Date " + sResult.AccountExpirationDate + "");
textbox.text("Account Lockout Time " + sResult.AccountLockoutTime + "");
textbox.text("Last Bad Password Attempt " + sResult.LastBadPasswordAttempt + "");
textbox.text("Last Logon " + sResult.LastLogon + "");
textbox.text("Last Password Set " + sResult.LastPasswordSet + "");
textbox.text("Password Never Expires " + sResult.PasswordNeverExpires + "");
textbox.text("Bad Logon Count " + sResult.BadLogonCount + "");
}
}
我尝试使用DirectoryEntry
和DirectorySearcher
,但是遇到accountExpires
,pwdLastSet
和lastLogon
的问题,因为结果是System.__ComObject
,我不知道如何转换。
如果有人可以帮助,请帮助。
谢谢