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.ps1What 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 column | Active Directory attribute |
|---|---|
username | sAMAccountName (logon name) |
first_name | givenName |
last_name | sn (surname) |
email | mail |
position | title (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.
- A Windows computer joined to the domain.
- The Active Directory module for PowerShell. Every domain controller has it. On other computers, install RSAT: Active Directory Domain Services and Lightweight Directory Services Tools.
- An account that can read user objects in Active Directory. Every domain user can do this.
1. Exporting the users
- Download the
ad_users_export.ps1script with the button above. - Open PowerShell in the folder where you saved the script.
- Run the export for the whole domain:
.\ad_users_export.ps1- 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"- The script creates the
ad_users_export.csvfile in the same folder and shows how many users it exported.
Script parameters
| Parameter | Description | Required | Example |
|---|---|---|---|
| -SearchBase | Exports only the users from this OU and its sub-OUs. Without it, the script exports the whole domain. | No | OU=Employees,DC=company,DC=local |
| -Path | The name or path of the output CSV file. | No | C:\Temp\users.csv |
Finding the path of an OU
- Open
Active Directory Users and Computers, clickView, and enableAdvanced Features. - Open the properties of the OU and go to the
Attribute Editortab. - Copy the value of the
distinguishedNameattribute. 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
- Log in to Redamp.io as an administrator. (If you are a partner, click a specific client to open their dashboard first.)
- Go to
Users, click theImport Usersbutton, and select the.CSVoption. - Upload the
ad_users_export.csvfile. Redamp.io reads the column names from the first row and sets the column types automatically. Check them in theSet data types to columnsstep. - 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.ps1If the execution policy still blocks the script, allow scripts for this PowerShell window only. Then run the script again:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy BypassThe 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.