• 0

LDAP Query for SQL: Unable to Retrieve Users from Distribution Group in Child OU


Question

Hello Neowin Community,

 

I have been struggling for a few days with this Windows Active Directory LDAP query for SQL and I am unsuccessful with get the desired results. I am trying to get a list of users in a distribution group that is in a child OU. Let's say that the distribution group is called "Network Group" in the "IT Network" child OU that is in the "IT Dept" parent OU. If the group was in the parent OU "IT Dept" I would have no problems, but since it is in the child OU "IT Network" under the parent OU "IT Dept", for some reason I am unable to successfully query. The following is my query (with internal.domain.com replacing my real network domain):

 

SELECT sAMAccountName as Login, CN as Name
FROM OPENQUERY
  (
    ADSI, 'SELECT sAMAccountname,CN
    FROM ''LDAP://internal.domain.com/DC=internal,DC=domain,DC=com''
      WHERE objectCategory=''person''
        AND objectClass=''user'' 
        AND memberOf=''CN=Network Group,OU=IT Network,OU=IT Dept,DC=internal,DC=domain,DC=com''
    ORDER BY CN'
  )

 

Can anyone point out what I may be doing incorrectly? I have tried switching the positions of "IT Dept" and "IT Network" perhaps thinking that there was an ordering issue with parent and child OUs, but that still did not work.

 

Thanks,

LTHuang

2 answers to this question

Recommended Posts

  • 0

I have no idea re LDAP queries, but in SQL you would use

memberOf IN ('CN=Network Group', 'OU=IT Network', 'OU=IT Dept', 'DC=internal' , 'DC=domain,DC=com')

 

'=' operator usually means you are trying to match on an exact string

 

* I btw probably didnt help with my answer....

  • 0

Thank you _kane81 for your suggestion, which I did implement and unfortunately did not resolve the issue, but rather encountering an "error occurred while preparing the query" message. Any thoughts on this? Regardless, thank you for your time and input, and I would appreciate any further suggestions if you have any. Thanks again. - LTHuang

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • To be fair, I haven't seen a BSOD since years ago, seriously. Windows has been pretty stable for me always.
    • Nobody is "shoving" anything down anybody's throats. The feature is turned off by default, so the user needs to explicitly enable it. How is that "shoving down" anything? Again: this is OPT-IN. If you don't like the feature for whatever reason, just ignore it or turn it off if you already enabled it.
    • Kioxia is Toshiba rebranded? Did not know that. 
    • I use to buy only Samsung and Crucial MX but things have change a lot in the last 5 years.   Western Digital Black ssd are very good. Corsair MP too (specially when it comes to gen 5) The Patriot 2TB Viper VP4300 Lite is a good cheap option with decent perf Crucial Txxx is pretty good too. I had bad exp with TeamGroup when they initially came out but i bought two TEAMGROUP T-Force Vulcan Z 2TB SLC Cache for my new computer because they were the cheapest 2 tb with any kind of cache and i've been pleasantly surprised.   You got to do your own research. Does it have dram cache? If yes which type of dram cache. Does it have a large SLC cache? If so how large is it? 20% of the drive? 30% of the drive? For example the TG 2TB i posted above has a 650GB SLC cache which is about 30% of the drive capacity. Is it TLC or QLC. I'd avoid QLC drive without any type of cache unless it's for storage they tend to perform badly with small writes. I'm not an expert so do your own research  https://www.techpowerup.com/ , https://www.tweaktown.com/ and https://www.tomshardware.com/ are usually good sources to know the real spec of a ssd and nvme specially the cache since a lot of manufacturer are not clear about this.
  • Recent Achievements

    • Week One Done
      SmileWorks Dental earned a badge
      Week One Done
    • Community Regular
      vZeroG went up a rank
      Community Regular
    • Collaborator
      Snake Doc earned a badge
      Collaborator
    • Week One Done
      Snake Doc earned a badge
      Week One Done
    • One Month Later
      Johnny Mrkvička earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      582
    2. 2
      Michael Scrip
      199
    3. 3
      ATLien_0
      198
    4. 4
      +FloatingFatMan
      129
    5. 5
      Xenon
      125
  • Tell a friend

    Love Neowin? Tell a friend!