Getting the PwdLastSet from ADSI

K

Kenneth Keeley

Hi,

I am looking for a sample of how to get the password last set for a user in
active directory in a format that we can read. I am using ASP.Net and C# I
have got as far as get the value. but I would like it as a normal date time
value. or at least display it as a string. if I use the code below the
response I get is "The password was last set :System.__ComObject" How do I
get this to a norma date format.

Thanks
Kenneth Keeley

// Create Active Directory Object.
DirectoryEntry AdsiEntry = new DirectoryEntry(_Path, _Domain + @"\" +
_AdminUserName, _AdminPassword);

// Create an Active Directory Search.
DirectorySearcher AdsiSearch = new DirectorySearcher(AdsiEntry);

// Find UserName in Active Directory.
AdsiSearch.Filter = "(SAMAccountName=" + UserName + ")";
SearchResult Result = AdsiSearch.FindOne();

// Get the users directory Entry.
DirectoryEntry UserEntry = Result.GetDirectoryEntry();

// Grab the "pwdLastSet" property.
pwdLastSetVal = UserEntry.Properties["pwdLastSet"].Value;

MyOutPut.Value = "The password was last set :" + pwdLastSetVal + "<br>";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top