I want to set the LastPasswordSet
attribute of a user in Microsoft Active Directory.
The .NET UserPrincipal
API exposes the LastPasswordSet
property as readonly.
Is there a way around this, to set the value (perhaps using ADSI)?
Edit:
MSDN provides the following example code:
usr.Properties["pwdLastSet"].Value = -1; // To turn on, set this value to 0.
usr.CommitChanges();
This forces the user to change their password at next logon. I presume if I replace -1 with a date-time in the relevant format, this will do what I want.
It does not, however, show how I get hold of the principal (presumably usr
). I'll upvote anything that helps me find this out.