Retired Microsoft Blog disclaimer

This directory is a mirror of retired "Decrypt My World" MSDN blog and is provided as is. All posting authorship and copyrights belong to respective authors.
Original URL: https://blogs.msdn.microsoft.com/alejacma/2008/03/25/how-to-get-password-expiration-date-with-system-directoryservices-c/
Post name: How to get Password Expiration Date with System.DirectoryServices (C#)
Original author: Alejandro Campos Magencio
Posting date: 2008-03-25T12:05:00+00:00


Hi, welcome back,


You may want to get Password Expiration Date for a given user withSystem.DirectoryServices. You may be temptedto use a code like the following:

DirectoryEntry entry = new DirectoryEntry(path);
object obj = entry.Properties["PasswordExpirationDate"].Value;
DateTime passwordExpirationDate = (DateTime)obj;


But "obj" is always null even if a "net user" command returns a valid password expiration date.


We can check that PasswordExpirationDate is not an available property in DirectoryEntry.Properties.PropertyNames collection.


So we could use a code like the following instead, which works:

DirectoryEntry entry = new DirectoryEntry(path)
ActiveDs.IADsUser native = (ActiveDs.IADsUser)entry.NativeObject;
DateTime passwordExpirationDate = native.PasswordExpirationDate;

I hope this helps.


Regards,



Alex (Alejandro Campos Magencio)


Share this article:

Comments:

Comments are closed.