Import Users Into Active Directory From CSV

Import Users Into Active Directory From CSV


If you need to create many new user accounts in a domain at once, it is extremely inefficient to create them all manually from the graphical console Active Directory Users and Computers (ADUC). In this article, we will take a look at a simple PowerShell script that allows you to import user data from a CSV/XLS file and create accounts for them in the Active Directory domain.

First of all, create a NewUser.xlsx file in Excel with the following header structure:

FullName;sn;givenName;company;department;title;telephoneNumber;City;sAMAccountName;Password

Fill the Excel file with the data of all users that you want to create in Active Directory (usually this data is provided from the personnel accounting system).

import users into active directory from csv

Export the Excel file to CSV format with commas as separators (File > Save as > File type: CSV, File name: new_as_users.csv). If you want to use “;” as a separator, you need to add the following argument to the Import-CSV cmdlet -delimiter “;”.

import users into active directory

To create new users in the domain, we will use the New-ADUser cmdlet from the Active Directory for Windows PowerShell module, so before running the PowerShell script, make sure that this module is installed on the server/computer from which you are performing users import.

Create an import_ad_users.ps1 file with the following PowerShell code (change the name of your domain and the Active Directory Organizational Unit (OU) in which you want to create users):

Import-Module ActiveDirectory

$Domain="@theitbros.cpm"

$UserOu="OU=Users,OU=UK,DC=theitbros,DC=com"

$NewUsersList=Import-CSV "C:\PS\new_as_users.csv"

ForEach ($User in $NewUsersList) {

$FullName=$User.FullName

$Company=$User.company

$Department=$User.department

$Description=$User.description

$givenName=$User.givenName

$title=$User.title

$City=$User.City

$telephoneNumber=$User.telephoneNumber

$sAMAccountName=$User.sAMAccountName

$sn=$User.sn

$userPrincipalName=$User.sAMAccountName+$Domain

$userPassword=$User.Password

$expire=$null

New-ADUser -PassThru -Path $UserOu -Enabled $True -ChangePasswordAtLogon $True -AccountPassword (ConvertTo-SecureString $userPassword -AsPlainText -Force) -CannotChangePassword $False -City $City -Company $Company -Department $Department –title $title –OfficePhone $telephoneNumber -DisplayName $FullName -GivenName $givenName -Name $FullName -SamAccountName $sAMAccountName -Surname $sn -UserPrincipalName $userPrincipalName

}

Note. Options-ChangePasswordAtLogon $True requires changing the user password at the first login, -CannotChangePassword $False – allows the user to change passwords by himself. If you create service accounts, you can specify -ChangePasswordAtLogon $False, -CannotChangePassword $True.

Run the script from the PowerShell command prompt, then open the ADUC console and make sure that new users appeared in the specified OU.

import users into active directory from csv powershell

As you can see, this PowerShell script allows the mass import of users into Active Directory in a few minutes. You can remove or add any user attributes to the script and CSV/Excel file from AD. A complete list of available user attributes in your domain schema can be displayed using the following cmdlet:

Get-ADUser –identity administrator –filter * -properties *|fl

import contacts into active directory

You may also like:

AD Account Keeps Locking Out Sometimes there are situations when AD account keeps locking out, this happen when you try to log on to a domain computer and getting an error on the ...
Store BitLocker Recovery Keys using Active Directo... In corporate segment one of the advantages of BitLocker Drive Encryption technology is the ability to store the Bitlocker recovery keys for encrypted ...
How to transfer FSMO Roles From a Failed Domain Co... In case domain controller, which owns FSMO (Flexible Single Master Operation) roles, is fail (virus attack, fatal software problems or catastrophic ha...
Installing Active Directory Users and Computers MM... One of the main Active Directory domain management tools is the MMC snap-in Active Directory Users and Computers (ADUC). The ADUC snap-in is used to p...
Change Default OU permissions in Active Directory By default, each newly created organizational unit (OU) in the access list includes read permission for the group Authenticated Users (built-in group)...

Add Your Comment