×
Export User from Active Directory – Powershell and ADUC

If you are a Windows system administrator and working on Active Directory then you might need to Export User Accounts from Active Directory in cases such as a Exchange and Active Directory migration.

You can also export users manually from the Active Directory. But, it would be very painful tasks, especially in a large organizations who have hundreds of users and accounts.

This is where PowerShell comes to the rescue, once again!

You can export Active Directory users either using the PowerShell or Active Directory GUI interface but with PowerShell, you can export All Active Directory users within a matter of seconds!

Further, you can combine the Admin Bundle for Active Directory, a trio of free utilities from SolarWinds, with PowerShell to achieve maximum control over exporting and importing Active Directory users during migrations. In this tutorial, we will show you how to export Active Directory users through two different methods as mentioned above!

Lets jump right into it!

Export AD Users with PowerShell

Before starting, make sure you are logged into an account with sufficient permissions to read from Active Directory.

Exporting users from Active Directory is a very simple task if your unfamiliar with active directory and using it.

In this section, we will show you how to export users from Active Directory with PowerShell.

List Users Attributes

Active directory users have a lot of associated attributes and you should know all available attributes before exporting them.

You can list all available attributes for a specific user using the following command:

get-aduser username -properties *

For example, you can see attributes of a user hitesh by running the following command in your PowerShell terminal:

get-aduser hitesh -properties *

You should see all available attributes in the following screen:

Powershell User Attributes command

Export All Active Directory Users by Name to CSV

You can export all AD users by name (First, Middle, and Last name) to the CSV file using the Get-ADUser command.

Before exporting users to the CSV, you can list all AD users with the following command:

Get-ADUser -Filter * -Properties * | Select-Object name

You should see all the users in the following output:

name
----
Administrator
Guest
DefaultAccount
krbtgt
Hitesh m. jethva
vyom h. jethva
user1
user2
jayesh
rajesh
manish
mitesh

Now, run the following command to Export all AD users to the CSV file name users.csv.

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

The above command will export all AD users to the users.csv file located in C: drive.

You can verify whether the users.csv is created or not using the following command:

dir ../../

Example:

export all AD users to csv files via Powershell

Next, go to the C: drive and open the users.csv file as shown below:

export all AD users and open CSV File example

Export All Active Directory Users by Name and LastLogonDate to CSV

You can also export all AD users from your domain to the CSV file with the First, Middle, and Last name in the first column and LastLogonDate in the second column.

First, List all AD users by Name and LastLogonDate with the following command:

Get-ADUser -Filter * -Properties * | Select-Object name, LastLogonDate

Next, export the above users with all details to the file user1.csv file as shown below:

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

Example:

List all AD users by Name and LastLogonDate

Export All Active Directory Users by Name and Email to CSV

You can also Export all AD Users from your domain to the CSV file with a Name and their Email Address.

First, List all AD users by Name and their Email address with the following command:

get-aduser –filter * -property * | Select-object Name, mail

Next, export the above users with all details in the user1.csv file as shown below:

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

Example:

Export All Active Directory Users by Name and Email to CSV

Export ALL Active Directory Users from a specific OU (Organizational Unit)

You can also export all AD users from a specific OU to the CSV file.

For example, lets List all AD users from the Account and Education OU by running the following command:

Get-ADUser -Filter * -SearchBase "OU=Account,DC=WEBSERVERADC,DC=COM"
Get-ADUser -Filter * -SearchBase "OU=Education,DC=WEBSERVERADC,DC=COM"

You should see all users of the Account and Education OU in the following screen:

Export ALL Active Directory Users from a specific OU

Now, you can export them to the user3.csv and user4.csv file using the following command:

Get-ADUser -Filter * -SearchBase "OU=Account,DC=WEBSERVERADC,DC=COM" | export-csv -path c:\user3.csv
Get-ADUser -Filter * -SearchBase "OU=Education,DC=WEBSERVERADC,DC=COM" | export-csv -path c:\user4.csv

Export Users with Active Directory GUI

In this section, we will show you how to export users with Active Directory GUI.

Export All Users from a Specific OU

To export all the users from Education OU follow the below steps:

1. Open Active Directory Users and Computers as shown below.

export users from ou aduc

2. Click on the Education OU and click on the Export button as seen in the top image. You should see the following screen:

Export users via ADUC

3. Provide the path and name of the file you want to save, select save as type to a csv and click on the Save button to export the users.

 

To Export All the Users from OU follow the below steps:

1. Open Active Directory Users and Computers, click on the Users, click on the Filter button in the top of the screen. you should see the following screen:

Export All the Users from OU

2. Select Users and click on the OK button. You should see only users in the Users OU as shown below:

Export All the Users from organizatinal unit

3. Click on the Export button in the top of the screen. You should see the following screen:

export users to file aduc

4. Provide the path and name of the file you want to save, select save as type to a csv and click on the Save button to export the users.

Now, go to the Documents folder and click on the user4.csv to see all the exported users in the following screen:

export file contents from the ADUC export

Export All Active Directory Users from Domain (From ALL Organizational Unit’s)

With Active Directory GUI, you can export users only from specific OU or folders.

If your organization has lots of OU’s and each OU has lots of users, you will need to export users from each OU one by one.

To resolve this issue and do a Bulk Export of Users, you can Create and use an LDAP query to List all Users from All OU’s, then export them to the CSV file.

You can follow the below steps to export all AD users:

1. Open Active Directory Users and Computers as shown below:

Active Directory Users and Computers

2. Right Click on the Saved Queries and click on the New Query button. You should see the following screen:

Saved Queries

3. Provide the name of your query and click on the Define Query button. You should see the following screen:

Define Query ADUC

4. Type your LDAP query in the Advanced tab and click on the OK button. You should see the following screen:

LDAP query Advanced Tab

5. Click on the OK button again. You should see all the users in the following screen:

LDAP query OK Button

6. Click on the Export button in the top of the screen. You should see the following screen:

LDAP query EXPORT all User to CSV

7. Provide the path and name of the file you want to save, select save as type to a csv and click on the Save button to export the users.

Now, go to the Documents folder (or wherever you saved your file) and click on the allusers.csv to see all the exported users in the following screen:

export filed

Conclusion

In the above tutorial, we learned how to Export All Active Directory users with PowerShell and Active Directory GUI. We hope you’ve learned how to complete this task from Both PowerShell and Active Directory Users and Computers, as well as using an LDAP query!

When you need to import the users, the free Admin Bundle for Active Directory from SolarWinds is invaluable.

The steps above should help you Export all AD Users from the entire Domain or from Specific OU only!

Feel free to ask any questions below in the comments if you have any.