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

Could someone explain to me why this does not work?

Import-Module ActiveDirectory 
$dcs = Get-ADComputer -Filter {DistinguishedName -Like "*Domain Controllers*"}

I get no results for this query.

Alternatively, could someone suggest a way using the module above that I can generate a list of systems on my domain that are NOT Domain Controllers (which is what I'm eventually trying to achieve).


share|improve this question
up vote 1 down vote accepted

It looks like a bug to me. -like operator doesn't work with all properties. It doesn't work with DistinguishedName, SID, ObjectClass, but it works with Name, DSNHostName, SamAccountName...

The following command will give you all domain controllers:

PS C:> Get-ADComputer -SearchBase "OU=Domain Controllers,DC=test,DC=local" -Filter *

This command will give you all computers that are NOT domain controllers:

PS C:> Get-ADComputer -LDAPfilter "(&(objectCategory=Computer)(!userAccountControl:1.2.840.113556.1.4.803:=8192))"

share|improve this answer

As all Domain Controllers should end up in the "Domain Controller" OU in AD when you promote the server, why not try:

$dcs = Get-ADComputer -SearchRoot "MYDOMAIN/Domain Controllers" -SearchScope onelevel

I think this is what you were trying to do above. Also be aware this is not a definitive way to find a Domain controller. Ideally you should search by member type.

$dcs = get-ADComputer -SearchRoot "MYDOMAIN" -SearchScope subtree -filter {ComputerRole -eq "DomainController" }

That should find any wayward DC's :)

As an aside, I unsuccessfully spent 30 mins trying to get the AD Module installed - its apparently a "New in 2008 R2" thing, and is a complete PITA if you don't have a 2008R2 machine handy :) I've used Quest AD Management Tools to devise the answer - the arguments are the same...

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.