Link to home
Start Free TrialLog in
Avatar of Rowdyone52
Rowdyone52

asked on

LDAP Query - Password Expires

Can you tell me why these dont work?

        private TimeSpan GetMaxPasswordAge()
        {
            DirectoryEntry entry = new DirectoryEntry("LDAP://SERVER1:3268");
            entry.AuthenticationType = AuthenticationTypes.Secure;

            DirectorySearcher searcher = new DirectorySearcher(entry, "(objectClass=*)", null, SearchScope.Base);
            SearchResult result = searcher.FindOne();
            TimeSpan maxPwdAge = TimeSpan.MinValue;
            if (result.Properties.Contains("maxPwdAge"))
                maxPwdAge = TimeSpan.FromTicks((long)result.Properties["maxPwdAge"][0]);
           
            return maxPwdAge.Duration();
        }

//-------------------
                    searcher = new DirectorySearcher(entry, filter, new string[] { "maxpwdage" });
                    result = searcher.FindOne();
                    if (result.Properties["pwdLastSet"].Count > 0)
                    {
                        if (result.Properties["pwdLastSet"][0].ToString() != "")
                            pwdLastSet = result.Properties["pwdLastSet"][0].ToString().ToLower();
                    }
Avatar of surajguptha
surajguptha
Flag of United States of America image

are you getting an exception now? what problems are u having?
Avatar of Rowdyone52
Rowdyone52

ASKER

The value for result.Properties["maxPwdAge"].Count  and  result.Properties["pwdLastSet"].Count  are always zero.  I dont get an exception.
List out all the properties and see if this property exists in the Search Result properties.
It may not be available or u might have been using the wrong property name
ResultPropertyCollection myResultPropColl;
myResultPropColl = mySearchResult.Properties;
Console.WriteLine("The properties of the " + 
                  "'mySearchResult' are :");
foreach( string myKey in myResultPropColl.PropertyNames)
{
   string tab = "    ";
   Console.WriteLine(myKey + " = ");
   foreach( Object myCollection in myResultPropColl[myKey])
   {
      Console.WriteLine(tab + myCollection);
   }
}

Open in new window

it isnt available, but I am looking all over the net and it should be.  I cannot figure out why I can't access that property name.
ASKER CERTIFIED SOLUTION
Avatar of surajguptha
surajguptha
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial