I have a UserPrincipal
object with a lot of properties, but I cannot find a property for the date that the password expires.
How can this be done?
PrincipalContext(ContextType) Initializes a new instance of the PrincipalContext class with the specified context type. PrincipalContext(ContextType, String) Initializes a new instance of the PrincipalContext class with the specified context type and name.
What does the principal "context" mean? designing post-click experiences that are consistent to the data established prior to the click.
System. DirectoryServices. AccountManagement manages directory objects independent of the System.
UserPrincipal(PrincipalContext) Initializes a new instance of the UserPrincipal class by using the specified context. UserPrincipal(PrincipalContext, String, String, Boolean) Initializes a new instance of the UserPrincipal class by using the specified context, SAM account name, password, and enabled value.
This is the simplest approach I was able to come up with...
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using ActiveDs;
//...
PrincipalContext domain = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(domain, "username");
DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject();
IADsUser native = (IADsUser)entry.NativeObject;
Console.WriteLine(user.GivenName + "'s password will expire on " + native.PasswordExpirationDate);
Note #1: ActiveDs
is listed on the COM tab of the Add Reference dialog as Active DS Type Library
Note #2: As far as I can tell, the PasswordExpirationDate
is in UTC time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With