hanumanth reddy

hanumanth reddy

  • NA
  • 15
  • 13.1k

How to get maxPwdAge by OrganizationUnit or Group wise in AD

Dec 19 2014 1:28 PM
I want to get maxPwdAge value for specific Organization Unit or Group wise.Anybody help me how to do it.

I am able to get domain level maxPwdAge like below
 long maxPwdAge=0;
string domain="LDAP://10.10.1.100/OU=Dev,DC=test,DC=com";
string adsiUserName="test";
string adsiPassword="test";
DirectoryEntry entry = new DirectoryEntry(domain, adsiUserName, adsiPassword, AuthenticationTypes.Secure);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
string filter = "(maxPwdAge=*)"; //"maxPwdAge=*";
mySearcher.Filter = filter;
SearchResult results = mySearcher.FindOne();
if (results != null)
{
Int64 pwdAge = (Int64)results.Properties["maxPwdAge"][0];
maxPwdAge = pwdAge / -864000000000;
}