The Get-ADUser cmdlet is your primary tool for filtering and exporting active user accounts from Active Directory. Whether you need to run a compliance audit or manage user licenses, knowing how to get AD enabled users is essential.
You have two main methods in PowerShell to retrieve enabled users: using the simplified -Filter parameter or the more complex -LDAPFilter parameter. We recommend the simplified -Filter method for clarity and ease of use.
Steps to obtain enabled users report using PowerShell using Get-ADUser cmdlet:
Method 1: Using the Get-ADUser Filter (recommended)
Import-Module ActiveDirectory
Get-ADUser -Filter {Enabled -eq $true} -Properties * |
Select-Object Name, SamAccountName, Title, Department, EmailAddress |
Export-Csv -Path "C:\Scripts\AD_EnabledUsers.csv" -NoTypeInformation
Method 2: Using the LDAP Filter
Import-Module ActiveDirectory
Get-ADUser -LDAPFilter "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))" -Properties sAMAccountName, givenName, sn, enabled |
Select-Object sAMAccountName, givenName, sn, enabled |
Export-Csv -Path "C:\Scripts\LDAP_EnabledUsers.csv" -NoTypeInformation
Generate and export enabled AD users to CSV (and other formats) using ADManager Plus:
Use PowerShell to generate a list of all enabled users and create a simple active users report.
Get-ADUser -Filter {Enabled -eq $true} | Export-CSV "C:\AD_EnabledUsers.csv" -NoTypeInformation
This command exports all active accounts with default properties for quick auditing.
Create detailed reports using the Get-ADUser filter (enabled true) with specific attributes.
Get-ADUser -Filter {Enabled -eq $true} -Properties Department,Manager,LastLogonDate,EmailAddress | Select Name,SamAccountName,Department,Manager,LastLogonDate,EmailAddress | Export-CSV "C:\DetailedEnabledUsers.csv" -NoTypeInformation
This PowerShell script exports active AD users and provides comprehensive details for HR reporting.
Generate a PowerShell enabled user list report from a specific organizational unit.
Get-ADUser -Filter {Enabled -eq $true} -SearchBase "OU=Sales,DC=contoso,DC=com" -Properties * | Select Name,Title,Department,Office | Export-CSV "C:\SalesEnabledUsers.csv" -NoTypeInformation
While PowerShell can be used to obtain the last logon details of users, it comes with several limitations.
This filters enabled users from the Sales OU specifically, which is useful for departmental audits.
| Parameters | Description |
|---|---|
| -Identity | Specifies an AD user object by distinguished name, GUID, security identifier, or SAM account name |
| -Filter | Specifies a query string using PowerShell Expression Language to retrieve multiple objects |
| -SearchBase | Specifies the AD path to search under (OU or container distinguished name (DN)) |
| -SearchScope | Specifies the scope of AD search (Base, OneLevel, or Subtree) |
| -Properties | Specifies which user properties to retrieve (default returns a limited set) |
| -LDAPFilter | Specifies an LDAP query string for filtering users |
Get-ADUser -Filter {Enabled -eq $true} -Properties * | Select Name,SamAccountName,Enabled
Export-CSV "$env:USERPROFILE\Desktop\EnabledUsers.csv" -NoTypeInformation
Export-CSV "C:\EnabledUsers.csv" -NoTypeInformation -Encoding UTF8
Get-ADUser -Filter {Enabled -eq $true} -Properties MemberOf | Select Name,@{N='Groups';E={$_.MemberOf -join ';'}}