Importing Active Directory users from a CSV file

Christopher Dakin

This article will show you how to create new Active Directory users from an externally created CSV delimited file, using a worked example.

We will first create a task to import a CSV file and then chain that to a create user task.

 

Gathering information for the user creation

First, we need to determine which user attributes are required or available, so that a CSV file can be prepared.

Go to Triggers & Automation->Automations. Click Create.

Start typing in Create Active Directory User in the task, and select this when it appears.

Take a look through all of the tabs to see all available text fields that you could use in the CSV file.

 

For Create Active Directory User, the available fields that can be used are:

  • Principal Name (the username)
  • Default password (if you turn the Generate Password slider off)
  • Assign Groups (can have multiple entries)
  • UPN
  • sAMAccountName
  • Organizational Unit
  • GivenName
  • Initials
  • Surname
  • Display Name
  • Description
  • Telephone
  • Office
  • Email
  • Home Page
  • Other Email (can have multiple entries)
  • Other Mobile Phone (can have multiple entries)

 

Then if you click on the Advanced link you can see other fields, which are:

  • Street Address
  • PO BOX
  • City
  • Postal Code/Zip
  • Country
  • Profile Path
  • Script Path
  • Home Directory
  • Home Drive
  • Home Phone
  • Pager
  • Mobile
  • Fax
  • IP Phone
  • Notes
  • Title
  • Department
  • Company
  • Manager

 

From the above, decide which information to use and how to format your CSV file.

For an example here, we will use Principal Name and sAMAccount name as one column, UPN, Organizational Unit, Given Name, Surname, Display Name, Email and Mobile.

 

Our example file with 3 users looks like this:

aduser1,aduser1@hypersocket.io,'OU=Test Accounts,DC=hypersocket,DC=io',ADUser,One,User One,aduser1@logonbox.com,000000000

aduser2,aduser2@hypersocket.io,'OU=Test Accounts,DC=hypersocket,DC=io',ADUser,Two,User Two,aduser2@logonbox.com,111111111

aduser3,aduser3@hypersocket.io,'OU=Test Accounts,DC=hypersocket,DC=io',ADUser,Three,User Three,aduser3@logonbox.com,222222222

 

Creating the automation to import the file

Go to Triggers & Automation->Automations. Click Create.

Give the new Automation a name and start typing in Import CSV in the task, and select this when it appears.

Take note of the Quote and Delimiter characters and ensure these match with the format of the CSV file you will be creating. You may wish to change the Quote character if you have these characters in user surnames and you may wish to change the delimiter character for similar reasons (for example if you wanted to create AD users and need to define an OU you could either surround the OU field with the quote character, or choose to use a different delimiter).

For our example, we can choose the default characters.

 

Select the Source tab.

For the Source, you may choose Upload (and upload the CSV file), Path (to read the file from a path directly on the LogonBox server) or Text (where you can paste the CSV text directly into a text field).

For this example. We select Upload, then click on Choose File and select the file.

Next, define the number of columns in the file in the Columns field. Our example has 8.

Then set whether the file has headers our not. The example does not so this can be left off.

 

As this will be a one time import, you may skip the Schedule tab.

In the Transaction tab, you can opt to turn on Fire Events. This will cause Audit Log events to be recorded. For this example, we will turn on Fire Events.

Transaction Required can be useful when chaining events as in this article, to protect the database from any corruption in the case of any failures, so turn this on also.

 

On the Repeat tab, leave Repeat as Never and Every as 0, as we will be triggering this automation manually.

In the Notes tab, you can optionally enter some information as to what you have created this trigger for if you want.

Click Create to create the new Automation.

You will now see the newly created Automation. Click on the + symbol to its left to expand the Automation. Now click on the + icon in the Import module, this will chain a new task to this one.

 

Creating the Import User automation

For the chained automation, give it a name such as Create User.

The event will already be filled with Import CSV which is correct.

Set the Triggers On to Success (i.e we only want the system to create users if the CSV file imported okay).

For Triggers Task, start typing in Create Active Directory User and select it from the list when it appears.

We have no specific conditions to meet so the Conditions tab can be left as default.

 

Select the Credentials tab. In Principal Name click on the ${} button to the right, then select the appropriate column from your CSV file. As this was the first column in our example, we select ${attr.column1}.

Set the Send Notification, Force Password Change (on first login) and Generate Password as per your preferences.

 

Select the Groups tab. If you want to add groups you have a choice. If you want all imported users to be in a particular group, you can start typing the group name and select it from a list. If you want to set the groups from the CSV file, you can click the ${} insert variable link and enter a column number. You can add multiple columns if you define multiple groups in the CSV.

Our example has no groups, so this will be left blank.

 

In the Account tab, do the same again for UPN, sAMAccountName and Organizational Unit as required.

In our example, these are columns 2, 1 and 3 respectively.

 

In the General tab for our example, we are using Given Name, Surname and Display Name, so we enter columns 4, 5 and 6 respectively.

 

In the Office tab is where our example will enter column 7 for the email.

 

And finally for the example, in the Telephones tab we can enter column 8 for the Mobile.

 

Click Create to complete the automation.

The expanded Import automation now shows the chained triggers.

 

 

Running the Import

As we set this up with no Schedule or Repeat, this task is set to run only on demand.

When ready, click the green gears icon next to the automation and click Run Now.

 

The Automation now runs and the users are created on your Active Directory.