Export AD Users to CSV with PowerShell

In this tutorial, you will learn how to export Active Directory users to CSV with PowerShell.

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.

To run the commands from this guide you need to make sure PowerShell is up to date and you have the RSAT tools installed. For this demo, I’m using a Windows 10 computer and using PowerShell version 5.1. You can check your version with this command.

$PSVersionTable

How to Export Active Directory Users to CSV

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

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.

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

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 all users command

Here is the CSV.

all user export csv example

Step 5: Export Users from a specific OU

export users from 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.

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

Export Users With the GUI AD Export Tool

If you need advanced exports such as exporting group membership to CSV then check out the examples below of the AD User Export Tool.

This GUI tool has the following benefits:

  • Export group members
  • Export OU path
  • Easily select attributes to export
  • Easy to use, no scripting required
  • Select multiple OUs or groups

You can download a free trial of the AD User Export Tool by clicking the button below.

Step 1: Open the AD User Export Tool

Once you have the AD Pro toolkit installed click on “User Export”

user export gui tool

Step 2: Choose Path to Export

In the search criteria box pick where you want to export from, you can pick the following:

  • Entire Domain – This will export all users in your domain
  • Select OU or Group – This allows you to select one or multiple OUs or groups to export.

In this example, I’m going to export all users from two security groups “Management_folders” and Management_Printers”.

select groups

Step 3: Pick AD User Fields to include in the Export

The attribute picker has over 50 attributes you can easily add or remove to the export.

select user attributes

For this example, I’m going to leave the default fields selected. You can always remove unwanted fields after exporting by deleting the columns in the CSV file.

Step 4: Click the Run button to preview the export

export example

The last step is to click the export button. Select your format and click “Export All Rows”

how to export to csv

You will be prompted to save the file. Give the file a name and save it to your computer.

Here is an example export.

csv example from gui tool

Include Users Group Membership in the CSV

One nice feature of the GUI tool is it will include the user’s group membership. Below is an example from my export. So for each user, it will show you which security groups they are a member of. Of course, you can just uncheck “memberOf” in the columns picker if you don’t want to see this info.

csv showing memberof column

Export Users with Active Directory Users and Computers

This method uses the Active Directory Users and Computers console to export users. If you need a very basic export with limited user fields then this option is for you. The one problem is it is limited to a single folder.

Step 1: Open Active Directory Users and Computers

Step 2: Browse to the container that has the users you want to export.

In my test environment, I’ll be exporting the users from the HR container.

Step 3: Click the export button

Now just browse to where you want to save the file, name it and change save as type to CSV.

I’ll open the CSV file in excel to verify it exported.

Yes, it worked.

How do you export all users to CSV?

The problem with exporting users from ADUC (Active Directory Users and Computers Console)is that it only exports users from a specific folder. If you have users organized into many different folders, you would have to export from each one of them.

To Export all Users you have two options.

  1. User Export GUI Tool
  2. PowerShell

Using the GUI tool you just select “Entire Domain”

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.scv

Summary

I just showed you 3 options for exporting Active Directory users to CSV. I recommend you try them all out and see which option is best for you. The built-in Microsoft console has the fewest options but if you just need a simple export then it works ok.

PowerShell can be a great option for exporting user accounts but it can be complex and challenging at times for quick solutions. If you are not into PowerShell and need an option to export from groups, OUs, and to select which fields to export then the AD User Export Tool is a great choice.

Related: How to export all groups and members from Active Directory

Recommended Tool: Permissions Analyzer for Active Directory

This FREE tool lets you get instant visibility into user and group permissions and allows you to quickly check user or group permissions for files, network, and folder shares.

You can analyze user permissions based on an individual user or group membership.

This is a Free tool, download your copy here.

35 thoughts on “Export AD Users to CSV with PowerShell”

  1. Thank you for posting this. It was very helpful for me today.

    Reply
    • No problem, glad it was helpful!

      Reply
    • It helped me immensely today as well. I don’t have access to the AD server, but I can ‘read’ AD with the MMC app. This was the first tutorial of several I had reviewed that got me exactly what I needed. Thank you, Mr. Robert Allen!

      Reply
  2. hi there
    i want to know how do i export all my users in AD with all permissions ??
    thanks

    Reply
    • What do you mean by all permissions? Are you wanting the security group membership?

      Reply
  3. Hey Robert,

    Thanks for putting this up. I’m curious if there is a way to list all users and all associated groups or organizational units in a single spread sheet?

    I’ve got some software that needs to auto-group users by AD Group or OU but operates outside Microsoft Active Directory. I’d love to be able to have a user generate a CSV that has person/user in a column and then what groups or OU’s they are associated with.

    Thx,

    Dave

    Reply
  4. Do you have video on import LDAP users in to AD?. I am trying to import our LDAP users to AD then to Azure. I am able to migrate from AD to Azure AD just need to work on the LDAP to AD part 🙂

    Reply
      • Hello, how do I exclude disabled accounts in the query? I only need active users

        Reply
        • Hi Lamin,

          Here is an example of returning only enabled users.

          Get-ADUser -Filter ‘enabled -eq $true’ -Properties * | Select-Object name | export-csv -path c:\export\allusers.scv

          Reply
  5. Excellent thank you much

    Reply
    • No problem

      Reply
  6. I am trying to export a list of our AD users as well as their “Log On To” permissions to a CSV file. How could I do this?

    Reply
    • CH, I think that is the logonWorkstation attribute. Try this

      Get-ADUser -Filter * -Properties * | select name, logonworkstation

      Reply
  7. Actually that script isnt what I was looking for.
    What I am referring to is when you open up the properties of a user and select the “account” tab, there is a button that says “log on to” and it shows what machines on the domain that that user is allowed to log on to.

    Reply
    • That attribute is userWorkstations

      Reply
      • Thanks! That worked perfectly!

        Reply
  8. I wanna to export from a particular active directory not all active directories

    Reply
    • Do you mean from a specific OU?

      Reply
  9. this was very useful, however I would like to get the unix attributes, such as uid and gid. These show up as {username} rather then the number when I use get-aduser username -properties *

    Reply
  10. Hi,

    Can you please tell me where I gone wrong with “Get-ADUser -Filter * -property * | Select-object Name, Title -SearchBase “OU=O365,OU=Users,DC=danielx64,DC=com,DC=au” | export-csv -path c:\export\allusers.csv”?

    Cheers

    Reply
    • Daniel,

      The -searchbase is in the wrong place. Try this

      Get-ADUser -Filter * -SearchBase “OU=O365,OU=Users,DC=danielx64,DC=com,DC=au” -property * | Select-object Name, Title | export-csv -path c:\export\allusers.csv

      Reply
  11. Hey Robert,

    I tried using the command, but my syntax may be wrong. Can you take a look?

    Get-AdUser -Filter * -SearchBase “OU=Digicel,OU=Bermuda,OU=Users,DC=BMU-DC-001,DC=digicelgroup,DC=local” -Property * | select-ObjectName, SamAccountName, PasswordExpired, PasswordLastSet, LastLogonDate, Enabled, DistinguishedName, DisplayName, GivenName, SurName|export-csv C:\Documents\output.csv

    Thanks,

    Reply
  12. Can we also export password?

    Reply
    • No. Active Directory stores them in an encrypted format so they cannot be exported.

      Reply
  13. Thanks, very helpful.

    Reply
  14. Server 2016, I would like to export users and groups they are in for instance “everybody”. Any ideas?

    Reply
  15. would like to export users based on “Office”

    Reply
    • Check out the user export tool I created, it included 26 user attributes that can be included in the export.

      Reply
  16. Hello Can you the steps to follow to extract ad users by licence ?

    Reply
  17. kindly send me command to get all users manager name without ou details included

    Reply
  18. Hi, question from support perspective.
    If you’re exporting all users and an extension attribute within an organization, would this have any impact on the users at all? Is it possible to slow down the system enough to impact users logging into the same servers?

    Reply
    • With the AD Pro Toolkit, I exported about 3000 users and it took 10 seconds. While it was running the domain controller CPU went from 7% to 30% for those 10 seconds. My test server has 1 CPU with 2GB ram, a very small server. In production, I would recommend 2 CPUs and at least 4GB ram.

      PowerShell uses very little CPU but took about 1 minute to export 3k users.

      Neither option should impact users logging in but that depends on the CPU/Mem usage before its run. What does your CPU/Mem usage show before running an export?

      Reply
    • Hi
      I would need to export all users who do not have the extensionAttribue1 “Azuresync” what is the powershell command

      Tanks

      Reply

Leave a Reply to Rahul Cancel reply