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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
Use the following command below...
dsquery computer "ou=test,dc=domain,dc=com" >> c:\computers.txt

Open in new window

That will find all of the computers in the test OU and export them to a text file.

Roy BeneVP/Director - IT | ISOCommented:
DSQUERY COMPUTER "OU=yourOU,DC=yourdomain,DC=com" -name * -scope subtree -limit 0 > c:\ComputersinOU.TXT

Hope this helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Newbie0000Author Commented:
I keep getting a "startnode" value error, I have the following:

dsquery computer "OU=MyTopOU,OU=OUwithinMyTopOU,DC=XXX,DC=XXX,DC=XXX,DC=XXX" >> C:\computers.txt
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Roy BeneVP/Director - IT | ISOCommented:
What's the error, specifically?

Also, why is your DC string so long? Try setting the subtree limit with the command I gave you, and see if that yields a different result.
Will SzymkowskiSenior Solution ArchitectCommented:

Based on how you have constructed the OU path it is incorrect.
dsquery computer "OU=MyTopOU,OU=OUwithinMyTopOU,DC=XXX,DC=XXX,DC=XXX,DC=XXX"

It should be the following...

Once you have done this it should resolve the issue.

Newbie0000Author Commented:
Thank you Will Szymkowski, I had the OU's backwards and that fixed my problem. I also added the >> computers.txt -limit 999 at the end so the whole syntax was:

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

Thank you all very much for the help, it's really appreciated.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.