Get-ADuser find two users when displayName is known

This topic contains 9 replies, has 5 voices, and was last updated by  Max Kozlov 1 year ago.

  • Author
    Posts
  • #55175

    Jeff Taylor
    Participant

    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

    Have you tried using -OR?

    • #55181

      Jeff Taylor
      Participant

      Yes that had worked earlier but only returns the first User

  • #55183

    Max Kozlov
    Participant

    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

    Mark Prior
    Participant

    Agree with max add the wildcards

  • #55186

    Dan Potter
    Participant

    -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

    Max Kozlov
    Participant

    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

    Dan Potter
    Participant

    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.

    • This reply was modified 1 year ago by  Dan Potter.
    • #55199

      Jeff Taylor
      Participant

      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

    Max Kozlov
    Participant

    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

You must be logged in to reply to this topic.