• 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

    • PC to remote Android phone possible?
    • The same idiots that provide their phone numbers and id to discord channels.
    • Wait, I thought there is no such thing as "eating disorder" and it is fat-phobic to say it!
    • 3.19.1 is out $ iperf3.exe -v iperf 3.19.1 (cJSON 1.7.15) CYGWIN_NT-10.0-19045 i9-win 3.6.4-1.x86_64 2025-07-15 07:55 UTC x86_64 Optional features available: CPU affinity setting, authentication, support IPv4 don't fragment, POSIX threads CRC32: BB95604E MD5: 201792CDD56975A3C68A7FE9F99D7B80 SHA-1: 92D6579AF3C917923B41BEC81C5BC80F6E4B4A9A SHA-256: 9A84118CD8EABB14A0FDA4FFA782DD5668E4461031D8AB119480BF9B09E3DC04 https://files.budman.pw/iperf3.19.1_64.zip $ iperf3.exe -c 192.168.10.10 Connecting to host 192.168.10.10, port 5201 [  5] local 192.168.10.9 port 19206 connected to 192.168.10.10 port 5201 [ ID] Interval           Transfer     Bitrate [  5]   0.00-1.00   sec   428 MBytes  3.58 Gbits/sec [  5]   1.00-2.01   sec   427 MBytes  3.55 Gbits/sec [  5]   2.01-3.01   sec   421 MBytes  3.55 Gbits/sec [  5]   3.01-4.01   sec   426 MBytes  3.55 Gbits/sec [  5]   4.01-5.00   sec   419 MBytes  3.55 Gbits/sec [  5]   5.00-6.01   sec   426 MBytes  3.55 Gbits/sec [  5]   6.01-7.01   sec   427 MBytes  3.55 Gbits/sec [  5]   7.01-8.01   sec   421 MBytes  3.55 Gbits/sec [  5]   8.01-9.00   sec   420 MBytes  3.55 Gbits/sec [  5]   9.00-10.01  sec   426 MBytes  3.54 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval           Transfer     Bitrate [  5]   0.00-10.01  sec  4.14 GBytes  3.55 Gbits/sec                  sender [  5]   0.00-10.02  sec  4.14 GBytes  3.55 Gbits/sec                  receiver iperf Done. Release notes: Security fixes seems like only updates. https://github.com/esnet/iperf/blob/master/RELNOTES.md    
    • Microsoft Edge 138.0.3351.109 by Razvan Serea Microsoft Edge is a super fast and secure web browser from Microsoft. It works on almost any device, including PCs, iPhones and Androids. It keeps you safe online, protects your privacy, and lets you browse the web quickly. You can even use it on all your devices and keep your browsing history and favorites synced up. Built on the same technology as Chrome, Microsoft Edge has additional built-in features like Startup boost and Sleeping tabs, which boost your browsing experience with world class performance and speed that are optimized to work best with Windows. Microsoft Edge security and privacy features such as Microsoft Defender SmartScreen, Password Monitor, InPrivate search, and Kids Mode help keep you and your loved ones protected and secure online. Microsoft Edge has features to keep both you and your family protected. Enable content filters and access activity reports with your Microsoft Family Safety account and experience a kid-friendly web with Kids Mode. The new Microsoft Edge is now compatible with your favorite extensions, so it’s easy to personalize your browsing experience. Microsoft Edge 138.0.3351.109 changelog: Fixed various bugs, feature updates, and performance issues for Stable Channel. Stable channel security updates are listed here. Feature updates Edge contextual capabilities in Business Chat work tab. Microsoft Copilot in Edge now supports page summarization and contextual queries to the Work tab for Microsoft 365 Copilot Business Chat. With this feature, users can ask Copilot contextual queries such as “summarize this page.” This feature also includes contextual prompt suggestions to help users ask relevant questions about open pages in Edge. Page summarization and contextual prompt suggestions is accessible for users when using Copilot through the Edge side pane. A Microsoft 365 Copilot license is required to use this feature. Administrators can control the availability using the EdgeEntraCopilotPageContext policy. Download: Microsoft Edge (64-bit) | 178.0 MB (Freeware) Download: Microsoft Edge (32-bit) | 161.0 MB View: Microsoft Edge Website | Release History Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      hhgygy earned a badge
      Week One Done
    • One Month Later
      hhgygy earned a badge
      One Month Later
    • One Year In
      NIKI77 earned a badge
      One Year In
    • Week One Done
      artistro08 earned a badge
      Week One Done
    • Dedicated
      Balaji Kumar earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      639
    2. 2
      ATLien_0
      237
    3. 3
      Xenon
      166
    4. 4
      neufuse
      144
    5. 5
      +FloatingFatMan
      122
  • Tell a friend

    Love Neowin? Tell a friend!