简体   繁体   中英

Get Active Directory users by a list of guid

I am using the UserPrincipal class in c#. I have a list of active directory guids.

How would i get the list of DirectoryEntries using this list?

I know how to do this using one guid but not for many guids.

You just need to iterate over your list of Guids, and fetch each user:

public List<UserPrincipal> FindAllUsers(List<Guid> allGuids)
{
   List<UserPrincipal> result = new List<UserPrincipal>();

   // set up domain context
   using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
   {
       foreach(Guid userGuid in allGuids)
       { 
          // find a user
          UserPrincipal user = UserPrincipal.FindByIdentity(ctx, userGuid);

          if(user != null)
          {
              result.Add(user);
          }
       }
    }

    return result;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM