Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 Nov 17 '10 at 0:52

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

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


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.