Announcement

Collapse
No announcement yet.

Simple LDAP query

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple LDAP query

    One simple LDAP query:
    I need to get all computers from OU=Test,OU=Computers?
    It would be something like:
    (objectCategory=computer)(???????what's next?????)
    Thanks

  • #2
    Re: Simple LDAP query

    I haven't done too much with ldap queries and cant test this right now but i think this is it:

    you will need to replace domain and xxx with your domain values.

    (&(objectCategory=computer)(ou=Test,OU=Computers,D C=domain,DC=XXX))

    p.s. for some reason it is putting a space between D & C that should not be there
    Last edited by wiredteknologies; 2nd February 2008, 04:10. Reason: typo
    Technology is only as good as those who use it

    My tech blog - wiredtek.wordpress.com

    Comment


    • #3
      Re: Simple LDAP query

      Unfortunately, I have tried this already, but w/o success:

      (&(objectCategory=computer)(OU=Computers,OU=Test,D C=test,DC=company,DC=net))
      BTW, there is 10 computer accounts in that OU

      Comment


      • #4
        Re: Simple LDAP query

        Is the DN of one of the computers "CN=computer,CN=Computers,CN=Test,DC= test,DC=company,DC=net"?

        Comment


        • #5
          Re: Simple LDAP query

          You could use the dsquery utility to return all a list of all computer objects within a specific organisational unit, using the following command:

          Code:
          dsquery computer OU=Computers,OU=Test,DC=test,DC=company,DC=net
          The default limit is to return 100 results but if youre querying only 10 computer objects this will not apply. If you do require to query more than the default number of object add -limt x to the above command, where x is the number to set the limit to.
          MCSA 2000/2003

          Comment


          • #6
            Re: Simple LDAP query

            dsquery would work as well, but you also need to make sure you have the correct DN structure in your query which i think may be your problem.... i also think this is where joeqwerty is going with his post.
            Technology is only as good as those who use it

            My tech blog - wiredtek.wordpress.com

            Comment


            • #7
              Re: Simple LDAP query

              Originally posted by stevana1969 View Post
              I need to get all computers from OU=Test,OU=Computers:
              (objectCategory=computer)(???????what's next?????)

              - ? -
              (&(objectCategory=computer)(OU=Computers,OU=Test ,D C=test,DC=company,DC=net))
              BTW, there is 10 computer accounts in that OU
              You are showing the LDAP Filter, you cannot provide the base DN here.
              With a filter you deal with the attributes of objects. Since your querying Computer objects, "OU" is not reconized because it is not a name of one of the standard computer attributes.

              Under the hood, dsquery performs a ldap query. the line is:
              Code:
              dsquery computer "OU=Computers,OU=Test,DC=test,DC=company,DC=net" -limit 0
              Where
              The (pre-defined) Filter: (objectCategory=computer)
              The startNode (base DN): OU=Test,DC=test,DC=company,DC=net
              The scope: subtree (default)
              Output attribute: distinguishedname (default)

              The CommandTex for a LDAP query would be
              LDAPQuery = <LDAP://BaseDN>;LDAPFilter;Out-Attributes;Scope

              In 'Saved queries' of Windows Server 2003 there is the "BaseDN" called "Query root", you can find this option on the 'edit page'.


              \Rems
              Last edited by Rems; 3rd February 2008, 00:30.

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment


              • #8
                Re: Simple LDAP query

                @Joeqwerty:
                DN of one of the computers is:
                CN=XP02,OU=Computers,OU=Test,DC=test,DC=company,DC =net
                When I try dsquery...., I get the next message:
                "dsquery failed:No superior reference has been configured for the directory servi
                ce. The directory service is therefore unable to issue referrals to objects outs
                ide this forest."

                Comment


                • #9
                  Re: Simple LDAP query

                  Do not add any spaces around the equal sign and not around the comma's, in the DN format.
                  And, wiredteknologies warned about a space that is automatically added here to break long "words" (a space between D & C that should not be there).

                  anyway,
                  The error indicates a problem in the last ,DC=net part of the dn in the startnode you provided.

                  \Rems

                  - EDIT -
                  To prevent long word breaks, add code and command lines allways between [code]...[/code]-marks, by selecting the code-line(s) and click the #-button.
                  stevana1969 can you paste the exact command line here, between the [code]-marks.
                  Last edited by Rems; 4th February 2008, 01:05.

                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  __________________

                  ** Remember to give credit where credit's due **
                  and leave Reputation Points for meaningful posts

                  Comment


                  • #10
                    Re: Simple LDAP query

                    Actually, Forum engine is adding some strange spaces, it was not intentional nor it was in the query.
                    Anyhow, finally, next code
                    Code:
                    dsquery computer "ou=Computers,ou=Test,dc=test,dc=company,dc=net"
                    produced some results:
                    "CN=XP02,OU=Computers,OU=Test,DC=test,DC=company,D C=net"
                    ....
                    "CN=XP01,OU=Computers,OU=Test,DC=test,DC=company,D C=net"

                    So, the question is, how to "translate" this into saved query in AD users and computers?

                    Thanks for help, guys

                    -Edit-
                    See, strange spaces between D and C
                    Last edited by stevana1969; 4th February 2008, 21:52.

                    Comment


                    • #11
                      Re: Simple LDAP query

                      That has been answered
                      http://forums.petri.com/showthread.p...2721#post92721

                      Create a new 'saved query'
                      - "Name": xxx
                      - "Description": xxx
                      - "Query root": <place the DN of the OU here>
                      - "Include all the subcontainers down the 'query root'": J/N
                      then, "Define Query..
                      - choose a "custom search", goto tab 'Advanced', add: (objectCategory=computer)

                      \Rems

                      This posting is provided "AS IS" with no warranties, and confers no rights.

                      __________________

                      ** Remember to give credit where credit's due **
                      and leave Reputation Points for meaningful posts

                      Comment

                      Working...
                      X