Where is the domain name in a UserPrincipal object?

后端 未结 2 896
后悔当初
后悔当初 2020-12-31 12:17

I\'m using the System.DirectoryServices.ActiveDirectory classes to find all Active Directory users. The code is very simple:

var context = new P         


        
2条回答
  •  误落风尘
    2020-12-31 12:41

    For AD DS, the value of msDS-PrincipalName is the NetBIOS domain name, followed by a backslash ("\").

    You can find it using :

    /* Retreiving the root domain attributes
     */ 
    sFromWhere = "LDAP://DC_DNS_NAME:389/dc=dom,dc=fr"; 
    DirectoryEntry deBase = new DirectoryEntry(sFromWhere, "AdminLogin", "PWD"); 
    
    DirectorySearcher dsLookForDomain = new DirectorySearcher(deBase); 
    dsLookForDomain.Filter = "(objectClass=*)"; 
    dsLookForDomain.SearchScope = SearchScope.base; 
    dsLookForDomain.PropertiesToLoad.Add("msDS-PrincipalName"); 
    
    SearchResult srcDomains = dsLookForDomain.FindOne();
    

提交回复
热议问题