How to Retrieve Only Enabled Users from the Active Directory

I'm trying to retrieve only enabled users in the AD. When I run this code line it returns the error. I tried using a filter as well to filter only enabled users for the requested info but it returns ALL users from every domain instead of just the single id.

Get-ADUser : A positional parameter cannot be found that accepts argument 'enabled -eq 'true''.

This is my code that is throwing the error.

Get-ADGroupMember -Identity 'Animal Shop A' | Get-ADUser -Filter '*' | Get-ADUser Where "enabled -eq 'true'" | Get-ADUser -Properties ('Mail')

This one returns ALL users from every domain

Get-ADGroupMember -Identity 'Animal Shop A' | Get-ADUser -Filter "enabled -eq'true'" | Get-ADUser -Properties ('Mail')

Is my syntax wrong on both of them? If I just want to return values from say "Animal shop A" and then "Animal Shop B"

1

5 Answers

.. or a little bit shorter this way:

Get-ADUser -Filter 'enabled -eq $true' -Properties mail | 
    Select-Object -Property Name,samaccountname,mail

Besides this I would recommend to use a -SearchBase. That's less stressful for the AD. ;-)

3
Get-ADUser -Filter * -Properties mail | Where { $_.Enabled -eq $True} | Select Name,samaccountname,mail

That will get all enabled users in your target domain that are enabled and display the name, username, and mail properties

1
get-aduser -filter 'enabled -eq "true"' -ResultSetSize $Null 

Important to know for both commands: You must work with an elevated powershell process. Otherwise the result may not be complete.

simply try below commands in powershell as administrator permission. As a guide, the first part will filter users, second part filtered enabled users and last part will give you export of results.

Get-ADUser -Filter * -Property Enabled | Where-Object {$_.Enabled -like “false”} | Export-Csv -Path C:\eport.csv -Encoding ascii -NoTypeInformation

hope to be useful for you.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest