How to List All Active (Enabled) Active Directory Users (PowerShell & dsquery)
Once an Active Directory domain has accumulated hundreds of accounts, former employees, and service users, sooner or later you need a clean export of only active (enabled) domain users – for an audit, license review, or printable directory. Here are the modern PowerShell one-liner, the classic dsquery LDAP command (fixing a common bitmask trap caught by readers!), and a quick reference table of userAccountControl codes.
Cleanest and most accurate method (PowerShell): run on a domain controller (or any admin PC with RSAT ActiveDirectory installed):
Get-ADUser -Filter 'Enabled -eq $true' | Select-Object Name, SamAccountName | Sort-Object Name
Method 1. PowerShell (Recommended for Windows Server 2012–2022)
The ActiveDirectory module checks enabled status accurately without manually calculating userAccountControl bitmasks. To export a neat CSV ready for Excel:
Get-ADUser -Filter 'Enabled -eq $true' -Properties DisplayName, Department, Mail | Select-Object DisplayName, SamAccountName, Department, Mail | Sort-Object DisplayName | Export-Csv -Path "C:\Temp\active_users.csv" -NoTypeInformation -Encoding UTF8
To limit the output to a specific Organizational Unit, simply add -SearchBase "OU=Users,DC=company,DC=local".
Method 2. Classic dsquery in Command Prompt (cmd)
Back in the day, I originally used userAccountControl=66048:
dsquery * domainroot -filter "(&(objectCategory=person)(objectClass=user)(userAccountControl=66048))" -limit 0 | dsget user -display | sort
Important reader correction: value 66048 matches only enabled accounts that also have “Password never expires” checked (512 + 65536). Normal enabled users with code 512 or 544 get missed!
To return every single enabled user via dsquery regardless of password flags, use the LDAP bitwise matching rule that excludes the ACCOUNTDISABLE bit (2):
dsquery * domainroot -filter "(&(objectCategory=person)(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))" -limit 0 | dsget user -display | sort
To list disabled users only instead, simply drop the exclamation mark: (userAccountControl:1.2.840.113556.1.4.803:=2).
Common Active Directory userAccountControl Codes
The userAccountControl attribute is a sum of bitwise flags (512 = normal enabled user, + 2 = disabled, + 65536 = password never expires). Most frequent values in production domains:
| Code | Account Status |
|---|---|
512 |
Enabled (normal user account) |
514 |
Disabled (ACCOUNTDISABLE) |
544 |
Enabled, password not required / change at logon |
546 |
Disabled + PASSWD_NOTREQD |
66048 |
Enabled, password never expires (512 + 65536) |
66050 |
Disabled, password never expires |
66080 |
Enabled, password never expires + PASSWD_NOTREQD |
532480 |
Domain controller (SERVER_TRUST_ACCOUNT) |
Related Windows domain tip: how to log in as a local administrator on a domain computer.
Whenever PowerShell is available, stick to Get-ADUser -Filter 'Enabled -eq $true'; if you are working in legacy cmd with dsquery, always use the bitwise :1.2.840.113556.1.4.803:=2 filter so half your active accounts do not silently disappear.
