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

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

Hope this helps.
1

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
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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.
0
Will SzymkowskiSenior Solution ArchitectCommented:
Newbie,

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...
ou=OUwithinMyTopOU,OU=MyTopOU,DC=XXX,DC=XXX,DC=XXX,DC=XXX

Once you have done this it should resolve the issue.

Will.
1
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.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.