DirectoryServices.AccountManagement principalsearcher OR queryfilter

Answered DirectoryServices.AccountManagement principalsearcher OR queryfilter

  • Wednesday, February 22, 2012 10:46 AM
     
      Has Code

    Is it possible with the principalsearcher to create a "OR" queryfilter

    I want to search for users containing a searchstring in either the DisplayName or the UserPrincipalName property but when I try I only get results where the searchstring appears in both properties.

    Dim domainContext As New PrincipalContext(ContextType.Domain)
    
    Dim up As UserPrincipal = New UserPrincipal(domainContext)
    up.DisplayName = "*" & searchString & "*"
    up.UserPrincipalName = "*" & searchString & "*"
    
    Dim searcher As PrincipalSearcher = New PrincipalSearcher(up)
    
    Dim results As PrincipalSearchResult(Of Principal) = searcher.FindAll
    
    For Each result As UserPrincipal In results
    
    Next

All Replies

  • Friday, February 24, 2012 7:36 AM
    Moderator
     
     Answered Has Code

    You can use principalsearcher to search for Display or UserprincipalName separately. 

    Like results1 for search Dispalyname, result2 for search UserPrincipalName.

    Foreach(var result in result2)
    {
     if(!result1.Contains(result))
     {result1.Add(result);
      }
    }



    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us