Script to export all computers in an OU and Sub-OUs into text file

Hello Everyone!

I am wondering if it is possible to have a script that exports a list of all computers in an OU and any sub OUs into a text file and have each computer name on a separate line. I do not have the faintest idea on where to begin so any help would be great!

LVL 22
Joseph MoodyBlogger and wearer of all hats.Asked:
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.

BrianIT ManagerCommented:
Have you tried just right clicking on the OU and selecting Export List...?  You then can do a CTRL H and find Computer and leave Replace blank to remove it.  That should work for you.

Joseph MoodyBlogger and wearer of all hats.Author Commented:
Does that grab any computers in sub OUs?
BrianIT ManagerCommented:
No it will not.  But I did just find this similar post that may help you.


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
Download and install the Server Resource Kit and use DSQUERY

dsquery computer -o rdn -limit 0 "cn=computers,dc=vch,dc=ca">Machines.txt
Joseph MoodyBlogger and wearer of all hats.Author Commented:
That worked perfect (used the vbs solution)! Thanks!
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
Active Directory

From novice to tech pro — start learning today.