How to search Global Catalog (whole forest) using PrincipalContext

后端 未结 1 710
夕颜
夕颜 2021-01-16 10:07
 myUserList AppUsers = new myUserList();    
 using (PrincipalContext pcxt = new PrincipalContext(ContextType.Domain, domainName))
            {
                User         


        
相关标签:
1条回答
  • 2021-01-16 11:08

    ok, i got it working. I just had to change my code like below.

     myUserList AppUsers = new myUserList();    
     using (PrincipalContext pcxt = new PrincipalContext(ContextType.Domain,  "my-global-catalogue-server.subdomain.domain.com:port", "DC=subdomain,DC=domain,DC=com"))
                {
                    UserPrincipal User = new UserPrincipal(pcxt);
                    User.EmailAddress = emailString;
    
                    PrincipalSearcher srch = new PrincipalSearcher(User);
                    foreach (var principal in srch.FindAll())
                    {
                        var p = (UserPrincipal)principal;
                        myUserRow User = AppUsers.NewUsersRow();
                        User.FirstName = p.GivenName;
                        User.LastName = p.Surname;
                        User.Email = p.EmailAddress;
                        AppUsers.AddUsersRow(User);
    
                    }
                }
    
    0 讨论(0)
提交回复
热议问题