Find all the folders within OU=Accounts in Active Directory and add to an arraylist

Find all the folders within OU=Accounts in Active Directory and add to an ArrayList

Note: To add or read properties from an Active Directory group you need to have special username and password like an Active Directory admin.


string userAcctName = ""
string displayName = ""
string userDept = "";

ArrayList usrAccountsfolders = new ArrayList();

// get all folders of UserAccounts.

string folderPath = ""int membercount = 0; int foldercount = 0;
folderPath = "LDAP://OU=UserAccounts,DC=aaaaaa,DC=com";
DirectoryEntry addGroup;
addGroup = new DirectoryEntry(folderPath, "Spluser""password");
Response.Write("The name is :: " + addGroup.Name.ToString() + "<br/>");

foreach (DirectoryEntry member in addGroup.Children)
{
    if (member.Name.Substring(0, 2) == "CN")
    { membercount += 1; }
    else if (member.Name.Substring(0, 2) == "OU")
    {  foldercount += 1;
       usrAccountsfolders.Add(member);
     }
    //Response.Write(member.Properties["displayName"].Value.ToString() + "<br/>");
}


No comments: