Export Active Directory data to CSV
How Active Directory exports to CSV and TSV work, what flattening changes, and how to keep the file readable and accurate in Excel and other tools.
Exporting Active Directory objects to CSV turns structured directory data into rows and columns that spreadsheets, scripts and reporting tools can read. The conversion is simple, but it is not neutral. Multi-valued attributes, timestamps, distinguished names and locale settings can all change what the exported file means. This review explains what an AD-to-CSV export changes, when it suits the job, and how to check that the result is still accurate after it is opened, edited or shared.
Is a CSV export suitable for your use?
CSV is a good fit for inventories, audits, license counts, stale-account reviews and handing a list to someone who works in a spreadsheet. Its main benefit is portability: almost any tool can open a delimited text file, and the file can be diffed, filtered and re-imported with scripts.
The main tradeoff is flattening. A directory object can hold lists, binary values and typed dates. A CSV cell holds one string. Anything that is not already a single text value has to be converted, joined or dropped, and spreadsheet software may then reinterpret what remains.
Another format is usually the better choice in three situations. If you need to move objects between directories or preserve multi-valued and binary attributes exactly, LDIF from ldifde is more appropriate. If the data is nested, such as users with their full group lists and nested group chains, JSON from ConvertTo-Json keeps the structure. If the export is only a quick human-readable list for a ticket or a message, a plain text list may be easier to read than a delimited file.
Which export method does "export AD to CSV" mean?
The phrase covers several different tools, and they do not produce the same output. Confirm which one is meant before comparing results.
| Method | What it exports | Notes |
| Active Directory Users and Computers, Export List | The columns currently shown in the console view | Saves tab- or comma-delimited text. Only visible columns are included, so add columns to the view first. |
| PowerShell ActiveDirectory module with Export-Csv | Any properties you request, shaped with Select-Object | The most control over columns, formatting and encoding. Requires RSAT or a domain controller. |
| csvde | LDAP attributes named on the command line | Uses LDAP attribute names rather than PowerShell property names, and always includes the distinguished name. Available where AD DS tools are installed. |
| ldifde | LDIF, not CSV | Listed for contrast. It keeps multi-valued and binary attributes in a directory-native format. |
"AD" can also refer to Microsoft Entra ID, formerly Azure AD. That is a different directory with different export tools, such as Microsoft Graph PowerShell or the admin portal's download options. The commands below apply to on-premises Active Directory Domain Services.
What the export actually changes
An export does not modify the directory. It reads object properties and writes a text representation of them. In that text, the stored values are converted rather than merely displayed differently. The points below are where meaning is most often lost.
- Property selection: Get-ADUser returns a default property set. Attributes such as Department, Title or MemberOf only appear if you request them with -Properties.
- Multi-valued attributes: if you pass memberOf or proxyAddresses straight to Export-Csv, the cell contains a type name such as Microsoft.ActiveDirectory.Management.ADPropertyValueCollection instead of the values. Join them into one string explicitly.
- Binary attributes: values such as thumbnailPhoto become System.Byte[] in the cell. The data is not exported.
- Timestamps: raw attributes such as lastLogonTimestamp and pwdLastSet are stored as large integers. They need conversion, or use computed properties like LastLogonDate and PasswordLastSet.
- Replication caveats: lastLogon is not replicated between domain controllers, and lastLogonTimestamp is replicated but deliberately not updated on every logon. The export is accurate for what the attribute stores, not necessarily for the most recent sign-in.
- Distinguished names: DNs contain commas, for example CN=Smith, Ann,OU=Staff,DC=example,DC=com. Correct quoting keeps them in one field. Naive comma splitting breaks them apart.
- Type information header: Windows PowerShell 5.1 adds a #TYPE line at the top of the file unless you use -NoTypeInformation. PowerShell 7 omits it by default.
A basic user export
Get-ADUser -Filter * -Properties DisplayName, EmailAddress, Department, Title, LastLogonDate |
Select-Object SamAccountName, DisplayName, EmailAddress, Department, Title, Enabled, LastLogonDate |
Export-Csv -Path .\ad-users.csv -NoTypeInformation -Encoding UTF8
Select-Object sets the column order and limits the export to the fields you need. Avoid -Properties * on large directories. It retrieves every attribute, which slows the query and produces columns full of unreadable type names.
Flattening group membership
Get-ADUser -Filter 'Enabled -eq $true' -Properties MemberOf |
Select-Object SamAccountName,
@{Name = 'MemberOf'; Expression = { ($_.MemberOf | ForEach-Object { ($_ -split ',')[0] -replace '^CN=' }) -join '; ' }} |
Export-Csv -Path .\ad-user-groups.csv -NoTypeInformation -Encoding UTF8
This version keeps only each group's common name, which makes the cell easier to read. It also loses information. The split is naive, so a group name containing an escaped comma is cut short. Two groups with the same name in different OUs also become indistinguishable. If you need exact identity, join the full distinguished names instead. Choose a joining separator that does not appear in the values and that differs from the file's delimiter.
Group members and computers
Get-ADGroupMember -Identity 'Finance Staff' |
Select-Object Name, SamAccountName, objectClass |
Export-Csv -Path .\finance-members.csv -NoTypeInformation -Encoding UTF8
Get-ADComputer -Filter * -Properties OperatingSystem, LastLogonDate |
Select-Object Name, OperatingSystem, Enabled, LastLogonDate |
Export-Csv -Path .\ad-computers.csv -NoTypeInformation -Encoding UTF8
Get-ADGroupMember returns direct members only unless you add -Recursive. With -Recursive, it lists nested users but not the intermediate groups, so the result answers a different question.
csvde and TSV output
csvde -f ad-users.csv -r "(&(objectCategory=person)(objectClass=user))" -l "sAMAccountName,displayName,mail,department" -u
Get-ADUser -Filter * -Properties Department |
Select-Object SamAccountName, Name, Department |
Export-Csv -Path .\ad-users.tsv -Delimiter "`t" -NoTypeInformation -Encoding UTF8
The -u switch tells csvde to write Unicode, which helps preserve non-ASCII names. Tab-separated output avoids most delimiter collisions, because commas inside DNs and display names no longer conflict with the separator. That makes TSV a practical choice when the data will be split by simple scripts.
Will the file stay readable and usable after sharing?
Most problems with an exported file appear after export, when another program interprets it. The file on disk may be correct while the view in a spreadsheet is not.
- Encoding: the default encoding of Export-Csv differs between Windows PowerShell 5.1 and PowerShell 7. Set -Encoding explicitly. In PowerShell 7, UTF8 means UTF-8 without a byte order mark. Use utf8BOM if the file will be double-clicked open in Excel, which relies on the BOM to detect UTF-8. Otherwise, names with accented or non-Latin characters may display incorrectly.
- Delimiter and locale: Excel uses the system list separator when opening CSV files. In regions where that separator is a semicolon, a comma-delimited file can land in a single column. Export-Csv -UseCulture matches the local separator. Importing through Excel's data import tool lets you choose the delimiter explicitly.
- Value reinterpretation: spreadsheets may strip leading zeros from employee IDs, show long numbers in scientific notation, and convert date-like strings into dates. Import those columns as text if the exact value matters.
- Formula interpretation: a cell beginning with =, +, - or @ may be treated as a formula when opened in a spreadsheet. If free-text attributes such as description could contain such values, review or neutralize them before sharing the file.
- Line breaks: attributes like description or info can contain newlines. Properly quoted CSV keeps them in one field, but some line-based tools and quick viewers will split the row.
- Editing round trips: saving the file from a spreadsheet can change its encoding, delimiter, quoting and date formats. If the CSV will feed a bulk-update script, validate the edited file before running the script.
A quick way to confirm that the export preserved meaning is to read it back and compare it with the source. Check row counts, then spot-check a few accounts with multi-valued or non-ASCII data.
$rows = Import-Csv -Path .\ad-users.csv
$rows.Count
$rows | Where-Object SamAccountName -eq 'asmith' | Format-List
For readers using assistive technology, a raw CSV is read as plain delimited text, which makes it hard to follow which value belongs to which column. If the export is meant for people rather than scripts, share it as a spreadsheet with a clear header row, or as a short plain-text summary. This article did not test specific screen readers, so check the intended reader's setup rather than assuming one format works everywhere.
Handling the exported data
Directory exports often contain names, email addresses, titles, managers and account status, which is personal and sometimes security-relevant information. Limit columns to what the task needs, store the file where access is controlled, and remove it when the work is done. Be cautious about pasting the file into online CSV converters or viewers. How a given service stores or retains uploaded data cannot be judged from its interface, so check its documented policy or convert the file locally with PowerShell or a desktop spreadsheet.
Gaps and limits of this review
No measurements, performance figures or rendering tests were supplied for this article, and none are claimed. The behavior described for PowerShell, csvde and Excel reflects general documented defaults, which can differ between versions, locales and organizational settings. Before relying on an export for compliance, migration or bulk changes, run the command in your own environment and verify a sample of the output.