none
LDAP Search for Computers in OU not yielding anything RRS feed

  • Question

  • Hello,

    Can anyone plz tell me why this query wont list Computer objects in the associated OU even though they do exist.  All I need to do is create a list of Windows 7 Computer objects, with a name beginning with E, located in the associated OU.  Im thinking my OU syntax is not correct. 

    (&(&(&(objectClass=computer)(OperatingSystem=Windows 7 Enterprise))(&(objectClass=computer)(name=E*)))(&(objectClass=computer)(distinguishedName=*OU=Acme ,OU=Mars,OU=PCs,OU=US,OU=Americas,DC=FlyByNite,DC=com)))


    Thanks for your help! SdeDot

    Wednesday, June 10, 2015 5:57 PM

Answers

  • The straight LDAP query string would be:


    (&(objectClass=computer)(operatingSystem=Windows 7 Enterprise)(name=e*))

    (Find all Windows 7 Enterprise computers that have a name that starts with the letter 'e')

    You can't specify an OU in an LDAP query.

    You have to target the root of the search at the container you want. That depends on the tool that is performing the LDAP query. If you don't know how to specify a starting container for the search, you will need to ask the vendor of your tool how to do that.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by SdeDot Thursday, June 11, 2015 5:59 PM
    Wednesday, June 10, 2015 10:00 PM
    Moderator

All replies

  • This part won't work:

    distinguishedName=*OU...

    Instead, start your search at the OU where you want. You also have objectClass specified 3 times. You only need to specify it once.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 10, 2015 6:28 PM
    Moderator
  • You could greatly simplify such a query by using Get-ADComputer in PowerShell:


    Get-ADComputer -LDAPFilter '(operatingSystem=Windows 7 Enterprise)' `
      -SearchBase 'OU=My OU,OU=Another OU,DC=fabrikam,DC=com'
    


    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 10, 2015 6:36 PM
    Moderator
  • Thanks Bill.

    I tried distinguishedName=OU..., but that doesn't work either.  What is the syntax to specify OU?


    Thanks for your help! SdeDot

    Wednesday, June 10, 2015 9:51 PM
  • I would use PS if I could Bill, but Im using the LDAP query inside a tool that doesn't understand PS.

    Thanks for your help! SdeDot

    Wednesday, June 10, 2015 9:51 PM
  • What are you using now.  You can set a searchbase in any tool.  You cannot do it the way you are trying to do it.


    \_(ツ)_/

    Wednesday, June 10, 2015 9:58 PM
  • I would use PS if I could Bill, but Im using the LDAP query inside a tool that doesn't understand PS.

    Thanks for your help! SdeDot

    If you are using a third party tool then you need to post in the forum for the vendor of that tool.  This forum is for scripting issues and not a general support forum.


    \_(ツ)_/

    Wednesday, June 10, 2015 9:59 PM
  • The straight LDAP query string would be:


    (&(objectClass=computer)(operatingSystem=Windows 7 Enterprise)(name=e*))

    (Find all Windows 7 Enterprise computers that have a name that starts with the letter 'e')

    You can't specify an OU in an LDAP query.

    You have to target the root of the search at the container you want. That depends on the tool that is performing the LDAP query. If you don't know how to specify a starting container for the search, you will need to ask the vendor of your tool how to do that.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by SdeDot Thursday, June 11, 2015 5:59 PM
    Wednesday, June 10, 2015 10:00 PM
    Moderator
  • Thanks Bill.

    By pointing the tool at the target OU and your example query, that did the trick.  I would like to use PS but cant.

    Thanks again for the advice.


    Thanks for your help! SdeDot

    Thursday, June 11, 2015 5:59 PM