Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good Morning
I have a list of sites in my domain and i want to access the user and contacts inside the sites of the active directory because I want to copy all contact details to users details. But I am only getting to the user objects of the domain not the user objects inside the sites.

Below I have tried to describe the tree structure of the domain the best I can

Domain
Sites
Site1
Site2
Users--this is the object I want to access
Contacts--this is na object I want to access
Site3
Users

What I have tried:

C#
public List<string> GetAllUsers(String Domain)
      {
          try
          {
              List<string> users = new List<string>();

              PrincipalContext oPrincipal = GetPrincipalContext(Domain);
              GroupPrincipal gPrincipal = GroupPrincipal.FindByIdentity(oPrincipal, IdentityType.SamAccountName, "Domain Users");

              if (gPrincipal != null)
              {
                  foreach (Principal p in gPrincipal.GetMembers(false))
                  {
                      users.Add(p.DisplayName);
                  }
              }

              return users;
          }
          catch (Exception ex)
          {

              throw ex;
          }
      }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900