Today I struggled with the problem of exporting a list of computers in a Windows Domain OU to a simple text file. The purpose of the text file is to act as an input for some other neat scripts.
I stumbled across a post on thebackroomtech.com that made the it seem like a piece of cake.
To export a list of all computers and non domain controller servers in an Active Directory OU, use dsquery.exe. For example, to export all computers in mydomain.com’s servers OU to machines.txt :
DSQUERY COMPUTER “OU=servers,DC=mydomain,DC=com” -o rdn -limit 1000 > c:\machines.txt
Simple and nice!