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:
Cancel
2 Comments   [ + ] Show Comments

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

1
not at a domain computer to test but according to

https://technet.microsoft.com/en-us/library/cc730720.aspx

it should be like this

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

http://social.technet.microsoft.com/wiki/contents/articles/2195.active-directory-dsquery-commands.aspx


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

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

Answers

Answer this question or Comment on this question for clarity