ldapsearch syntax

Marius - Roma 391 Reputation points
2020-09-17T14:28:28.297+00:00

I need to perform a demo using LDAP.
I am not an LDAP expert neither a Linux expert, but I was able to install ldapsearch on a Linux box and (copying from several sites) to perform a query like the following one:

ldapsearch -x -b "DC=mydomain,DC=local" -H ldap://192.168.1.1 -D "CN=Administrator,CN=Users,DC=mydomain,DC=local" -W "objectclass=user" -W sAMAccountname

It works, but the result includes either the AD users and other objects.
Can anybody please help me refining the query so that I can list all the AD users and nothing else?
A guide to use ldapsearch to query Active Directory would be really apreciated....
Regards
marius

Windows for business Windows Server User experience Other
{count} votes

3 answers

Sort by: Most helpful
  1. Lucas 266 Reputation points
    2020-09-18T20:51:40.247+00:00

    This is not the correct syntax.

    ldapsearch -x -b "DC=mydomain,DC=local" -H ldap://192.168.1.1 -D "CN=Administrator,CN=Users,DC=mydomain,DC=local" -W "objectclass=user" -W sAMAccountname

    remove the trailing "-W sAMAccountname

    The final query would be:

    ldapsearch -x -b "DC=mydomain,DC=local" -H ldap://192.168.1.1 -D "CN=Administrator,CN=Users,DC=mydomain,DC=local" -W "objectclass=user"
    
    0 comments No comments

  2. Marius - Roma 391 Reputation points
    2020-09-20T09:03:24.78+00:00

    Many thanks.
    I suspect that my question was unclear.
    I want to list only users.
    With my original query I see few information (name, dn and sAMAccountname) either of users and of computers and of some groups.
    If I remove the trailing "-W sAMAccountname" I see a lot of additional information about all the same objects.
    What I need, instead, is listing information about only users ("John Doe", "Jane Doe" and so on) without computers and groups.
    How should I enter the query?
    Regards
    marius

    0 comments No comments

  3. Vicky Wang 2,736 Reputation points
    2020-09-22T08:18:51.067+00:00

    Hi,@Marius - Roma
    Thank you for the update.
    The grammatical problem you mentioned may be beyond the scope of knowledge of our forum. Specific to the user's grammar, I recommend you to find a senior engineer. They can give you more professional help.
    reference:https://support.microsoft.com/en-in/hub/4343728/support-for-business
    Thank you for your understanding and support
    Best wishes
    Vicky

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.