How to import users into Active Directory from CSV

Manually creating user accounts in Active Directory is a time-consuming and error-prone task, especially when onboarding multiple employees at once. A more efficient and reliable method is to import users into Active Directory in bulk directly from a structured CSV file. This approach transforms a multi-hour task into one that takes a matter of minutes, ensuring consistency and accuracy across all new accounts. In this article, we will explore how to leverage the Import-Csv PowerShell script to create users in Active Directory from a CSV and compare how swiftly it can be done with ADManager Plus, an Active Directory management solution.

Importing users into Active Directory: PowerShell vs. ADManager Plus

Windows PowerShell

Follow these steps carefully to run the Import-Csv PowerShell script to import Active Directory users in bulk:

  1. Prepare a CSV file: Create a CSV file that contains all the user information. The column headers in your CSV must correspond to the Active Directory user attributes.
  2. Here's a sample CSV file.
  3. Install prerequisites: Ensure the Remote Server Administration Tools (RSAT) and the ActiveDirectory module for PowerShell are installed on your machine.
  4. Run the script: Open Windows PowerShell as an administrator and execute the following script:
    Import-Module ActiveDirectory
    $users = Import-Csv-Path$csvPath
  5. Verify if the users are present in the Active Directory Users and Computers console.
ADManager Plus

To import users using ADManager Plus:

  1. Prepare a CSV file with the required attributes and corresponding user data.
  2. Log in to ADManager Plus and navigate to Management > User Management > User Creation > Create Bulk Users.
  3. Click the Import button and browse and select your CSV file.
  4. Click Next and select the container where you would like to create the users.
  5. Click Create Users.

Verify if the users have been created using the Recently Created Users report in ADManager Plus.

CSV template and format requirements

Your CSV file should include these essential columns for basic user creation. You can add more columns to populate other Active Directory attributes.

Column Description Example
FirstName User's first name Alex
LastName User's last name Smith
SamAccountName Login name for pre-Windows 2000 systems Alexsmith
Password Initial password pass@123!
EmailAddress Email address alex.smith@company.com
Department Department name IT
Title Job title System Administrator
Office Office location New York
PhoneNumber Office phone +2-777-0709

Example scripts and use cases using the Import-Csv Powershell cmdlet

When working with Active Directory, importing CSV files using PowerShell can solve a wide range of real-world IT scenarios. Below are common use cases with corresponding PowerShell scripts.

Example 1: Importing new hires into Active Directory

The HR department has provided a list of employees who have joined recently. You need to create accounts for these users in Active Directory for all of them without manual entry. The following script creates all users listed in the CSV file and enables their accounts.

Import-Module ActiveDirectory
$Users = Import-Csv "C:\newhires.csv"
foreach ($User in $Users) {
New-ADUser `
-SamAccountName $User.SamAccountName `
-GivenName $User.GivenName `
-Surname $User.Surname `
-DisplayName $User.DisplayName `
-UserPrincipalName "$($User.SamAccountName)@example.com" `
-Path $User.OU `
-EmailAddress $User.EmailAddress `
-Department $User.Department `
-Title $User.Title `
-AccountPassword (ConvertTo-SecureString $User.Password -AsPlainText -Force) `
-Enabled $true
}

How to automate this: With ADManager Plus, you can configure a scheduled automation to automatically fetch a CSV file from a specified location and provision the users in Active Directory.

Example 2: Importing Active Directory users and adding them to security groups

You need to create new accounts for interns and add them to the Interns security group automatically. You can use the following script:

$Users = Import-Csv "C:\interns.csv"
foreach ($User in $Users) {
# Create the user
New-ADUser -SamAccountName $User.SamAccountName -GivenName $User.GivenName `
-Surname $User.Surname -Path $User.OU `
-AccountPassword (ConvertTo-SecureString $User.Password -AsPlainText -Force) -Enabled $true
# Add to group
Add-ADGroupMember -Identity "Interns" -Members $User.SamAccountName
}

How to automate this: With ADManager Plus, you can simply add a memberOf column in your CSV file or apply a user provisioning template to automatically add users to the Interns group.

Common parameters

Parameter Description
-Path This parameter specifies the path to the CSV file you want to import. You can specify multiple paths.
-LiteralPath This parameter specifies the path to the CSV file, but unlike -Path, it does not interpret any characters. Use this if your file path contains characters that PowerShell might otherwise interpret specially, like square brackets [].
-Delimiter This parameter defines the character that separates the values in your file. The default is a comma (,). Use this if your file is semicolon-separated (;), tab-separated (\t), or uses another character.
-Header This parameter provides custom headers for the columns. This is extremely useful if the CSV file you are importing does not have a header row. The values are assigned to the headers in order.
-UseCulture This parameter tells Import-Csv to use the list separator from your system's current regional settings as the -Delimiter.

Limitations of using the Import-Csv PowerShell cmdlet to import Active Directory users

While PowerShell helps administrators perform bulk actions, relying on it for critical and routine tasks like bulk user creation comes with significant risks and limitations that are often overlooked.

  • Steep learning curve and complexity: Writing a robust script requires a deep understanding of cmdlets, error handling, logic, and Active Directory attributes, and not every IT team member is a PowerShell expert.
  • Highly error-prone: A small typo in your CSV file like an incorrect OU path or a logical error in the script can result in hundreds of users being created in the wrong place, with incorrect permissions, or not being created at all. The time spent cleaning up such a mistake can far exceed the time saved by automation.
  • Significant security risks: To execute a user creation script, the person running it often requires high-level permissions in Active Directory, such as being in the Domain Admins group, to create user objects. This violates the principle of least privilege and makes it difficult to safely delegate the task to help desk staff or junior administrators.
  • Lack of an audit trail: Native PowerShell scripts do not create a clear, accessible audit log. If a mistake is made, it can be difficult to determine who ran the script, when it was run, and what specific actions were performed on each object.

Benefits of choosing ADManager Plus over PowerShell

ADManager Plus, an Active Directory management solution, is purpose-built to solve the challenges associated with using PowerShell scripts, helping admins import users into Active Directory in a few clicks.

  • Script-free user creation: ADManager Plus comes with an intuitive interface and requires no scripting, removing the risk of script typos and logical errors.
  • Secure task delegation: In ADManager Plus, you can create a help desk role and grant uses with this role permission to perform only bulk user creation using a specific template. This allows you to delegate the task securely, without ever giving the technician elevated permissions in native Active Directory.
  • Comprehensive audit reports: ADManager Plus offers audit reports for technicians with details such as who created which users, when they did it, and what attributes were set. This helps organizations meet requirements of compliance standards with ease.
  • Faster and efficient: With features like user creation templates, you can preconfigure all necessary attributes, from group memberships and Exchange policies to Microsoft 365 licenses. This turns a multi-step scripting process into a simple, three-click task that can be completed in minutes, not hours.

Import Active Directory users instantly with ADManager Plus

FAQs

The most common method is to use the Import-Csv PowerShell cmdlet to read user data from your file and loop through it with the New-ADUser cmdlet to create an account for each row, as shown in the scripts above. Alternatively, you can also use ADManager Plus to import users into Active Directory users in a few clicks.

Follow the steps below to find the path of an OU:

  • Open Active Directory Users and Computers.
  • Right-click the OU where you would like to create users.
  • Go to Properties and select the Attribute Editor tab. Find the distinguishedName attribute and copy its value.

Yes. You can add more columns to your CSV file and add them as parameters in the $userParams section of the script. For example, if you would like to add a Department attribute, add this as a header in the CSV file and -Department $user.Department in the $userParams section of the script.

Yes, this script uses the ActiveDirectory module, which is compatible with PowerShell 7, provided you have RSAT installed.

The one-stop solution to Active Directory Management and Reporting
Email Download Link