Querying Active Directory (AD) for user accounts is one of the most frequent administrative tasks an IT professional performs. Whether you need to audit compliance, filter by department, isolate disabled accounts, or build custom reports, getting accurate user data quickly is essential to keeping an enterprise environment running smoothly.
Export Active Directory Users with PowerShell Get-ADUser Cmdlet
To query Active Directory using PowerShell, you must have the Remote Server Administration Tools (RSAT) installed with the Active Directory module enabled. Below are the common administrative use cases filtering by department, identifying missing account details, and auditing security configurations.
1. Find Enabled Users in a Specific Department
To extract a clean inventory of active personnel belonging to a single team (e.g., the ‘Sales’ department), run the following script:
# Find all enabled users in a specific department and export to CSV
Get-ADUser -Filter "Department -eq 'Sales' and Enabled -eq '$true'" `
-Properties Department, Title, EmailAddress |
Select-Object Name, UserPrincipalName, Department, Title |
Export-Csv -Path 'C:\sales_users.csv' -NoTypeInformation -Encoding UTF8
The -Filter statement targets the directory level. Adding explicit properties ensuring Department, Title, and EmailAddress are fully cached before we pipe into Select-Object. The final step appends -Encoding UTF8 to safeguard special characters in names or titles.
2. Find Active Users with No Manager Assigned
Auditing the directory for orphaned accounts or incomplete profiles is a standard cleanup task. However, Get-ADUser handles blank database fields strangely, and standard -eq $null queries inside the server-side filter often fail or throw errors.
# Find enabled users who do not have a manager assigned
Get-ADUser -Filter "Enabled -eq '$true' and -not (manager -like '*')" `
-Properties Manager |
Select-Object Name, UserPrincipalName, SamAccountName
By structuring the filter with -not (manager -like ‘*’), the command successfully pulls active users whose manager distinguishedName attribute is completely empty.
Alternative:
The same search can also be performed using LDAP syntax. This approach directly queries Active Directory attributes and is often preferred in environments already using LDAP-based filtering.
# Same query using -LdapFilter
Get-ADUser -LdapFilter "(&(!(userAccountControl:1.2.840.113556.1.4.803:=2))(!(manager=*)))" ` -Properties Manager | Select-Object Name, UserPrincipalName, SamAccountName 3. Identify Users Whose Passwords Never Expire
Accounts configured with non-expiring passwords present a significant security vulnerability if left unaudited. This snippet isolates those specific accounts:
# Find users whose password never expires
Get-ADUser -Filter "PasswordNeverExpires -eq '$true'" ` -Properties PasswordNeverExpires | Select-Object Name, UserPrincipalName, PasswordNeverExpires Alternative:
Unlike the standard -Filter syntax, -LdapFilter works directly with raw Active Directory attributes and bitwise operators, making it especially useful for advanced userAccountControl queries.
# Same query using -LdapFilter (DONT_EXPIRE_PASSWORD flag = bit 65536)
Get-ADUser -LdapFilter "(userAccountControl:1.2.840.113556.1.4.803:=65536)" ` -Properties PasswordNeverExpires | Select-Object Name, UserPrincipalName, PasswordNeverExpires The Reality: Pain Points with Native Microsoft Tools
While PowerShell is an undeniably robust tool, executing routine audits through the console regularly poses friction for IT administrators.
Cryptic OID and Syntax Rules: Standard properties like Enabled map to complicated bitwise calculations behind the scenes inside the Active Directory database (e.g., the userAccountControl attribute).
Quoting and Variable Traps: Filter blocks are notoriously picky about strings vs. boolean variables. Misplacing a single quote (‘) or double quote (“) will stop an automated script entirely or return incomplete results.
Performance Penalties: Forgetting to restrict search parameters via -SearchBase or poorly sequencing a pipeline causes massive datasets to process locally, running the risk of domain controller timeouts.
The Skill Barrier: Team members who aren’t PowerShell experts or helpdesk technicians cannot easily construct these multi-line pipelines on the fly, escalating simple request tickets to senior tier-3 engineers.
The Modern Alternative: Zero-Code Searching With EasyEntra
If you prefer to skip the syntax headaches entirely, EasyEntra provides a flexible workspace where you can search, view, and extract AD records instantly.
Search results are produced in real-time as you type, similar to the experience in Microsoft’s own admin center consoles.
EasyEntra includes an intelligent feature called Relaxed Typing. It lets you enter simple, human-readable statements right into a search bar. The software then instantly transforms your plain text into valid, highly-optimized backend LDAP statements:
| Human-Readable Query in EasyEntra | Automated Backend LDAP Translation |
|---|---|
| enabled=true | (!(userAccountControl:1.2.840.113556.1.4.803:=2)) |
| disabled=true | (userAccountControl:1.2.840.113556.1.4.803:=2) |
| type=user | (&(objectCategory=person)(objectClass=user)) |
| passwordlastset<2024-08-01 | (pwdlastset<=133668504000000000) |
Beyond Relaxed Typing, the EasyEntra search field also accepts raw LDAP queries directly. You can paste a filter into the search bar and immediately see live results. This makes it easy to test and refine LDAP queries without writing scripts first.
Search and Export via EasyEntra
- Open the EasyEntra AD Search panel and select the specific Organizational Unit (OU) you want to look inside.
- Input your parameters naturally using relaxed typing (e.g., type=user department=sales enabled=true).
- Right-click the column header bar to check or uncheck properties like Title, Email, or Manager to build your custom view.
- Click any column header to sort the records. When you’re ready, click the Export List button on the toolbar and save it directly as a .csv or .tsv file.
By utilizing Advanced AD Searching combined with the Select AD Columns interface, what used to take complex multi-line scripting is reduced to a few intuitive clicks.