Rowdyone52
asked on
LDAP Query - Password Expires
Can you tell me why these dont work?
private TimeSpan GetMaxPasswordAge()
{
DirectoryEntry entry = new DirectoryEntry("LDAP://SER VER1: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.Contain s("maxPwdA ge"))
maxPwdAge = TimeSpan.FromTicks((long)r esult.Prop erties["ma xPwdAge"][ 0]);
return maxPwdAge.Duration();
}
//-------------------
searcher = new DirectorySearcher(entry, filter, new string[] { "maxpwdage" });
result = searcher.FindOne();
if (result.Properties["pwdLas tSet"].Cou nt > 0)
{
if (result.Properties["pwdLas tSet"][0]. ToString() != "")
pwdLastSet = result.Properties["pwdLast Set"][0].T oString(). ToLower();
}
private TimeSpan GetMaxPasswordAge()
{
DirectoryEntry entry = new DirectoryEntry("LDAP://SER
entry.AuthenticationType = AuthenticationTypes.Secure
DirectorySearcher searcher = new DirectorySearcher(entry, "(objectClass=*)", null, SearchScope.Base);
SearchResult result = searcher.FindOne();
TimeSpan maxPwdAge = TimeSpan.MinValue;
if (result.Properties.Contain
maxPwdAge = TimeSpan.FromTicks((long)r
return maxPwdAge.Duration();
}
//-------------------
searcher = new DirectorySearcher(entry, filter, new string[] { "maxpwdage" });
result = searcher.FindOne();
if (result.Properties["pwdLas
{
if (result.Properties["pwdLas
pwdLastSet = result.Properties["pwdLast
}
are you getting an exception now? what problems are u having?
ASKER
The value for result.Properties["maxPwdA ge"].Count and result.Properties["pwdLast Set"].Coun t 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
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);
}
}
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.