EASYENTRA Blog

News & Updates

How to Search and Export Active Directory Users with Get-ADUser 

How to Search and Export Active Directory Users with Get-ADUser

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 EasyEntraAutomated 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

  1. Open the EasyEntra AD Search panel and select the specific Organizational Unit (OU) you want to look inside.
  2. Input your parameters naturally using relaxed typing (e.g., type=user department=sales enabled=true).
  3. Right-click the column header bar to check or uncheck properties like Title, Email, or Manager to build your custom view.
  4. 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.

Free 30-minute demo

try 30 days for free

GET EASYENTRA NEWS

Opt out at any time

“One of the best products I've used.”
Gary Shurland
Chief Information Officer, Mirick, United States
“This tool has been invaluable in streamlining our IT processes.”
Tyson Mckay
Chief Information Officer, Southwest Network, United States
“This product has been a miracle for our Help Desk. EasyEntra has completely transformed how we handle Microsoft 365 administration.”
Doug Sanders
Manager of Technical Customer Support, Junior Achievement USA, United States
“Your product is such a time saver. I love it!”
Scott Fehr
IT Infrastructure, MEC Aerial Work Platforms, United States
“It's a good product and saves us lots of time for these ongoing quick admin tasks.” 
Chris McFerran
Managing Director, CTech IT Solutions Ltd, United Kingdom
“EasyEntra has significantly streamlined our workflow, simplifying everything. It feels almost like a revolution.”
Johan Sadelius
IT-chef, Arjeplog Kommun, Sweden
I greatly appreciate your assistance and willingness to enhance the already outstanding product.”
Michael I. Wilson
Executive Director of Information Technology, Archdiocese Of Washington, United States
“It's great not having to switch back and forth between the O365 admin center and the Teams admin center to assign groups. I am sold!”
Thomas Madden
Director Information Technology, AutoPayPlus, United States
“I would highly recommend organizations use the solution as it greatly simplifies various tasks.”
S. Roger Singh
Chief Technology Officer, Prasad & Company LLP, Canada
“EasyEntra is time-saving. Love the copy/paste for user/computer groups and the copy to new user.”
Damian Nita
Associate Network Administrator, Shenandoah Valley Westminster-Canterbury, United States
“EasyEntra has transformed our daily IT operations by simplifying user management, reducing errors, and enhancing overall efficiency.”
Henrik Nefling
IT- and Digitalization Manager, Animal Protection Denmark, Denmark