Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 wrote this cmdlet:

Search-ADAccount -filter {(enabled -eq $true)} -Users Only -SearchBase "ou=FirstOU,dc=domain,dc=com" -AccountInactive -TimeSpan 30

But it outputs an error:

Search-ADAccount : A parameter cannot be found that matches parameter name 'fil
At line:1 char:25
+ Search-ADAccount -filter <<<<  {(enabled -eq $true)} -UsersOnly -SearchBase "
ou=FirstOU,dc=domain,dc=com" -AccountInactive -TimeSpan 30
    + CategoryInfo          : InvalidArgument: (:) [Search-ADAccount], Paramet
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory

Could someone please help?

share|improve this question
up vote 4 down vote accepted

Filter it the other way?:

Search-ADAccount -UsersOnly -AccountInactive -TimeSpan 30.00:00:00 |where {$_.enabled}
share|improve this answer

The Search-ADAccount does not accept a parameter -Filter. Please see the Technet docs or Get-Help Search-ADAccount for a list of supported parameters.

You can pipe the results of the search to Where-Object to get only enabled users:

Search-ADAccount -UsersOnly -SearchBase "ou=FirstOU,dc=domain,dc=com" -AccountInactive -TimeSpan 30 |
    Where-Object { $_.Enabled -eq $true }
share|improve this answer

Try the get-ADUser command, it allows you to filter your users better.

get-aduser -filter (enabled -eq $true) -searchbase "OU"

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.