I’m using the System.DirectoryServices library to query against a LDAP directory. I’m seeing all the text attributes fine, but I need to retrieve some operational attributes like pwdChangedTime. I get an object not set to an instance of the object’ type error when trying to get these properties.
using (DirectorySearcher search = new DirectorySearcher(dirCon,
ldapSearchFilter.Replace("{cn}", cn),
new string[] {"*","+"},
SearchScope.Subtree))
{
foreach (SearchResult sr in search.FindAll())
{
la = new LdapAccount();
la.pswdUpdateTime = DateTime.ParseExact(sr.GetDirectoryEntry().Properties["pwdchangedtime"].ToString(), dateFormat, null);
...
}
I see all the text attributes but it won’t find any operational attributes.
Doing some testing locally I see the property
pwdlastseton theSearchResult, so I wonder if the property names are not what you expect them to be.There is also a
PropertyNamescollection on the SearchResult Properties collection that might be useful. Also, when I have queried AD before I did not callGetDirectoryEntry()but just enumerated the properties directly from the SearchResult.