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.
Follow these steps carefully to run the Import-Csv PowerShell script to import Active Directory users in bulk:
Import-Module ActiveDirectory
$users = Import-Csv-Path$csvPath
To import users using ADManager Plus:
Verify if the users have been created using the Recently Created Users report in ADManager Plus.
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 |
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.
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.
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.
| 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. |
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.
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.
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:
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.