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>";
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>";