public static string GetProperty(SearchResult searchResult, string PropertyName)
{
if (searchResult.Properties.Contains(PropertyName))
{
You can get the last password set date of a directory user in human readable form as easy as pie. To achieve this you can use nullable LastPasswordSet property of UserPrincipal class from System.DirectoryServices.AccountManagement namespace.
If User must change password at next logon option is checked then LastPasswordSet property returns null value. Otherwise it returns the last date and time the password was set in type DateTime.
using(PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, Username);
//? - to mark DateTime type as nullable
DateTime? pwdLastSet = (DateTime?)user.LastPasswordSet;
...
}
MSDN: UserPrincipal
MSDN: LastPasswordSet