Take the 2-minute tour ×

I'd like to get the list of all computers within a domain. Searching on google I've found

dsquery * domainroot -filter "(objectClass=Computer)" -attr name -l -d my.domain > c:\computers.txt

Is there any way to have the same result excluding domain controller(s)?

share|improve this question

migrated from stackoverflow.com Nov 17 '10 at 0:52

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 1 down vote accepted

You can typically omit the -d my.domain portion if running the query on any domain computer. The LDAP filter (userAccountControl:1.2.840.113556.1.4.803:=8192) returns all Domain Controllers, negating the filter will exclude DCs.

dsquery * domainroot -filter  "&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=8192)" -attr name -l > c:\computers.without.dcs.txt

Detailed description of the UserAccountControl attribute is available on MSDN as well as Microsoft's support site.

share|improve this answer

If you want to use PowerShell to accomplish this, install the Quest PowerShell Commands for Active Directory on a computer with PowerShell version 2 and issue the following command.

Get-QADComputer | ?{$_.ComputerRole -ne 'DomainController'} | Select Name | Export-Csv Without-DCs.csv

This will give you a CSV file in the current directory with all computers except Domain Controllers.

share|improve this answer

Your Answer


