DSQUERY to find all computer names in an OU

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?

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. - Newbie0000 5 years ago
    • 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 - SMal.tmcc 5 years ago
  • Thanks so much, I did not know that. - Newbie0000 5 years ago

Answers (1)

Answer Summary:
Posted by: SMal.tmcc 5 years ago
Red Belt

Top Answer

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


  • dsquery.exe computer -name %COMPUTERNAME% > file.txt - aragorn.2003 5 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ