I am trying to find all the computer names in a specific OU in AD (Server 2008 R2) and print them out to a text file using DSQUERY. Does anyone have the proper syntax? I am running from cmd line as admin and not having much luck?

Answer Summary:
2 Comments   [ + ] Show Comments


  • Thank you, I used:

    ou=OUwithinMyTopOU,OU=MyTopOU,DC=XXX,DC=XXX,DC=XXX,DC=XXX >> computers.txt -limit 999

    Everything worked perfect!
    Thanks again.
    • remember the >> will append to the file not replace it (> replaces the file) so if you run it more then once it will be full extra machine names
  • Thanks so much, I did not know that.
Please log in to comment

Answer Chosen by the Author

not at a domain computer to test but according to


it should be like this

dsquery computer OU=Sales,DC=Contoso,DC=Com > file.txt
also see this for other dsquery calls


Answered 07/08/2015 by: SMal.tmcc
Red Belt

  • dsquery.exe computer -name %COMPUTERNAME% > file.txt
Please log in to comment


Answer this question or Comment on this question for clarity