Export AD Users To CSV With PowerShell - Active Directory Pro

In this tutorial, I’ll show you two options on how to export Active Directory Users to CSV. I’ll also show you how to export users from an OU, and get specific user attributes like last logon, email addresses, state, city, and so on.

Table of contents

  • Option 1. Export AD Users to CSV with the AD Pro Toolkit
  • Option 2. Export AD Users to CSV with PowerShell
  • How to Export All Users from Active Directory

Option 1. Export AD Users to CSV with the AD Pro Toolkit

In this first example, I’ll Export Users with the AD Pro Toolkit. This tool makes it very easy to export all users or users from an OU and groups.

Step 1. Download the AD Pro Toolkit

Click here to download a free trial

You can install the tool on your local computer or a server.

Step 2. Open Export Users Tool

Under Management Tools click on “Export”.

Step 3. Select Path

By default, the tool will export all domain users. To export users from a specific OU or group click the browse button. In this example, I have selected two OUs that I want to export users from.

select and ou or group

Step 4. Add or Remove user Attributes

Click “Columns” to add or remove user attributes. You can also include custom attributes by clicking the “Add Custom Attribute” button. To re-arrange the attributes click the up or down arrows.

select attributes to export

Step 5. Click “Run” to generate a list of users

This will display the accounts you want to export and all the properties you selected. This gives you a preview of what will be exported.

Step 6. Export the list of users

Click “Export” to export the list of AD users to CSV. Alternatively, you can select to export to Excel or PDF.

click the export button

Below is an example from my export. So for each user, it will show you which security groups they are a member of and all the other user attributes I selected. Of course, you can just uncheck “memberOf” in the columns picker if you don’t want to see this info.

csv example of exported users

Option 2. Export AD Users to CSV with PowerShell

Here are the steps to export Active Directory users to CSV using PowerShell.

Step 1: Get-ADUser PowerShell Command

To export users with PowerShell, the Get-ADUser cmdlet is used. This command will get user accounts from Active Directory and display all or selected attributes. It’s important to know how this command works so you can export the data you need.

The most important thing to remember is how to display all the user attributes. This will come in useful when you want to export only specific account details.

The below command will get all user attributes for a single user.

get-aduser -identity username -Properties *

Change the “username” to a user in your domain.

Pay attention to the left column. These are the user attribute names and the values on the right. In example 4, I’ll show you how to select specific attributes to include in the export.

get ad user powershell command

Related: How to bulk modify user attributes

Step 2: Export to CSV command

Add “export-CSV -path” to the end of the command to export to a CSV file. See the below example, I’m exporting all the properties for this user to c:\temp\export.csv.

get-aduser -identity username -Properties * | export-csv -path c:\temp\export.csv
export-csv cmdlet

You should now have a CSV export of all user properties for a single user.

Step 3: Export specific user attributes

If you don’t want to export all user attributes then use the “select-object” command and enter only the attributes you need. If you have followed along from the beginning then you know how to find the attribute names, if not then jump to example 2.

In the below example I’ll export the DisplayName, City and State.

get-aduser -identity username -Properties * | select DisplayName, City, State | export-csv -path c:\temp\export.csv

Step 4: How to export all users

To export all users remove (-identity) and add (-filter *) to the command. In the below example I’m exporting all users and selecting displayname, city, company, department, EmailAddress, and telephonenumber.

get-aduser -filter * -Properties * | select displayname, city, company, department, EmailAddress, telephonenumber | export-csv -path c:\temp\export-all.csv

Here is what this looks like in PowerShell.

export ad user preview powershell

Here is the CSV.

export example csv

Step 5: Export Users from a specific OU

export users from an ou

To export users from specific OUs use the “-SearchBase” command and the “distinguishedName” value of the OU.

In the below example I’m getting all the users in my accounting OU.

Get-ADUser -Filter * -Properties * -SearchBase "OU=Accounting,OU=ADPRO Users,DC=ad,DC=activedirectorypro,DC=com" | select displayname, DistinguishedName, Enabled

Here is the PowerShell output.

export users from ou powershell

Then add export-csv -path to the end to export this to CSV.

Get-ADUser -Filter * -Properties * -SearchBase "OU=Accounting,OU=ADPRO Users,DC=ad,DC=activedirectorypro,DC=com" | select displayname, DistinguishedName, Enabled | export-csv -path c:\temp\export-ou.csv

At this point, you should be able to export single, all users, or users from a specific OU. I also showed you how to export all or specific user attributes.

Below are a few more PowerShell examples.

Export only enabled users

To get just the enabled user accounts you need to add a filter that searches for enabled = true.

Get-ADUser -Filter {Enabled -eq $true} -properties * | select-object samaccountname,givenname,surname,Enabled | export-csv -path c:\export\exportusers.csv

Export users to CSV with last logon date

get-aduser -Filter * -Properties * | select displayname, LastLogonDate | export-csv -path c:\temp\export_lastlogon.csv

How to Export All Users from Active Directory

To export all users from Active Directory, follow these steps.

  1. Open the Export Users Tool
  2. Click “Run”
  3. Click the “Export” button and select CSV.
  4. Optionally, click the Columns button to add or remove attributes.

With PowerShell, the below command will export all users to CSV. This will just export the user’s name, you will need to add additional attributes as needed.

Get-ADUser -Filter * -Properties * | Select-Object name | export-csv -path c:\export\allusers.csv

I hope this article helped you learn how to export ad users to csv. You may also want to see our guide on how to export group members to csv.

Related Articles

  • Export Group members to csv
  • Get all Email Address from Active Directory
  • Find Accounts with Password Not Required

Tag » Active Directory Explorer Export Users