Exporting users from Active Directory

Learn how to export users from your on-premise Active Directory to a CSV file with a PowerShell script, and import them into Redamp.io in bulk.

Do you manage your users in a local (on-premise) Active Directory? Then you do not have to type them into Redamp.io one by one. Our PowerShell script exports them to a CSV file, and you import that file into the Redamp.io console.

Download ad_users_export.ps1

What the script exports

The script exports every enabled user account that has an email address. It skips disabled accounts and accounts without an email address.

CSV columnActive Directory attribute
usernamesAMAccountName (logon name)
first_namegivenName
last_namesn (surname)
emailmail
positiontitle (job title)

Redamp.io gives all imported users the User role. You can change the role of each user before you finish the import.

Prerequisites

We recommend that you run the script directly on your Active Directory server (domain controller). It already has everything that the script needs, so you do not have to install anything.

1. Exporting the users

  1. Download the ad_users_export.ps1 script with the button above.
  2. Open PowerShell in the folder where you saved the script.
  3. Run the export for the whole domain:
.\ad_users_export.ps1
  1. Or export only one organizational unit (OU) and the OUs inside it. Do this, for example, when your service accounts are in a different OU:
.\ad_users_export.ps1 -SearchBase "OU=Employees,DC=company,DC=local"
  1. The script creates the ad_users_export.csv file in the same folder and shows how many users it exported.

Script parameters

ParameterDescriptionRequiredExample
-SearchBaseExports only the users from this OU and its sub-OUs. Without it, the script exports the whole domain.NoOU=Employees,DC=company,DC=local
-PathThe name or path of the output CSV file.NoC:\Temp\users.csv

Finding the path of an OU

  1. Open Active Directory Users and Computers, click View, and enable Advanced Features.
  2. Open the properties of the OU and go to the Attribute Editor tab.
  3. Copy the value of the distinguishedName attribute. This is the value for -SearchBase.

2. Checking the CSV file

Open ad_users_export.csv and look through the rows. Delete the rows of service accounts, shared mailboxes, and other accounts that you do not want to import.

The file is UTF-8 encoded, so names with diacritics stay correct.

3. Importing the file into Redamp.io

  1. Log in to Redamp.io as an administrator. (If you are a partner, click a specific client to open their dashboard first.)
  2. Go to Users, click the Import Users button, and select the .CSV option.
  3. Upload the ad_users_export.csv file. Redamp.io reads the column names from the first row and sets the column types automatically. Check them in the Set data types to columns step.
  4. Click Review Import, check the users, and finish the import.

You can let Redamp.io send each imported user an email invitation. With it, the user sets a password and pairs their devices. For all the steps of the import, see Importing users .

Troubleshooting

Windows blocks the script

Windows can block a script that you downloaded from the internet. Unblock it once, then run it again:

Unblock-File .\ad_users_export.ps1

If the execution policy still blocks the script, allow scripts for this PowerShell window only. Then run the script again:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

The ActiveDirectory module is missing

The error The specified module 'ActiveDirectory' was not loaded means that the computer does not have the Active Directory module. Run the script on a domain controller, or install RSAT as described in Prerequisites .

No users were found

The script shows No enabled users with an e-mail address were found. when no enabled user in the domain or OU has the mail attribute. Check the -SearchBase value, and check that your users have an email address in the E-mail field of their properties.