Get-ADuser find two users when displayName is known

Welcome Forums General PowerShell Q&A Get-ADuser find two users when displayName is known

This topic contains 9 replies, has 5 voices, and was last updated by

 
Participant
2 years, 1 month ago.

  • Author
    Posts
  • #55175

    Participant
    Points: 48
    Rank: Member

    I'm trying to get properties for 2 known users using displayName but getting no results that should be there

    Get-ADUser -Filter {(displayName -Like "Admin_ML") -And (displayName -Like "AdminMR")} -Credential $creds -Properties *

    What am I missing with my Get-ADUser syntax?

    thanks

  • #55180
    AK

    Participant
    Points: 14
    Rank: Member

    Have you tried using -OR?

    • #55181

      Participant
      Points: 48
      Rank: Member

      Yes that had worked earlier but only returns the first User

  • #55183

    Participant
    Points: 0
    Rank: Member

    May be you should use (displayName -Like "Admin_ML*") -And (displayName -Like "AdminMR*")
    node the * in filter.
    May be your Displaynames differ from your vision ? spaces after text or so on...

  • #55184

    Participant
    Points: 20
    Rank: Member

    Agree with max add the wildcards

  • #55186

    Participant
    Points: 21
    Rank: Member

    -And will not work here. You're saying the displayname of single account must match both conditions.

    Note in a large environment this query is not ideal. Displayname is in the anr set.

    'Admin_ML','Adminmr' | % {get-aduser -filter 'anr -eq $_'}

  • #55188

    Participant
    Points: 0
    Rank: Member

    Hmm, I'm copy/paste -And. of course there should be -or instead

    Dan, on my measurements
    Get-ADUser -Filter {(anr -Like "Admin_ML*") -or (anr -Like "Adminmr*")
    two times faster than
    'Admin_ML*','Adminmr*' | % {get-aduser -filter 'anr -like $_'}

    may be because of two requests in your variant 🙂

  • #55193

    Participant
    Points: 21
    Rank: Member

    anr -eq and don't use wildcard. Always try to avoid the like operator as the query has to check the condition against all users.

    ex. My displayname contains characters before and after potter, dan
    get-aduser -Filter "anr -eq 'potter, dan'" -Properties displayname

    ANR are indexed attributes so the query is much faster than any other.

    • #55199

      Participant
      Points: 48
      Rank: Member

      Thanks Dan and everyone, I wasn't at all familiar with ambiguous name resolution until this conversation and it did the trick for me (without the wild cards). I found my two users.

  • #55227

    Participant
    Points: 0
    Rank: Member

    thanks, Dan, I personally doesn't know that I can use -eq with anr and it works even with partial names 🙂
    on my test domain with 10000+ users first request 5 times faster than -like

    next requests with the same euery seems cashed and request times almost equal

The topic ‘Get-ADuser find two users when displayName is known’ is closed to new replies.