Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

add comment

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
add comment

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
add comment

Your Answer

 
discard

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.