The creation of user accounts in Active Directory is one of the routine tasks of a system administrator. Of course, you can create users manually using the graphical wizard in Active Directory Users and Computers. But what if you need to create dozens or even hundreds of users? Such a task will take a lot of time and attention and will be very tiring. In this post, we will look at several ways of automating the bulk creation of new users in AD from a list in a CSV file. using the built-in Windows tools.
How to Create Multiple Users in Active Directory with CSVDE
The classic command line tool csvde.exe (located in the %windir%/system32 directory on Windows Server) allows you to create new objects in Active Directory in bulk from the list in the CSV file.
Hint. Previously, we showed how to import/export Active Directory objects using CSVDE.
Your CSV file should contain at least the following columns:
DN, sAMAccountName, UserPrincipalName, sn, givenname, objectClass
- DN – Distinguished name of a new user object in LDAP format. For example, CN=George Davis,OU=Users,OU=Service,DC=theitbros,DC=com
- sAMAccountName – unique logon username (up to 20 characters)
- UserPrincipalName – in the format username@theitbros.com
- Sn – user surname
- GiveName
- ObjectClass – user
Open Excel and fill in the table with the details of the users that you are going to create in the AD.
Save the XLSX file as a CSV file with a comma as the delimiter.
Now you can bulk create users in AD from a list in a CSV file. Log on to the Active Directory domain controller, open the elevated command prompt, and run the following command:
Csvde -i -f "C:\PS\bulk_ad_user.csv" –k
The csvde will create new user accounts in Active Directory. Open the ADUC console (dsa.msc) and check that the new user accounts appear in the target Organizational Unit in AD.
The inability to set passwords for new user accounts is the main drawback of the csvde utility. Also note that new user accounts will be disabled after creation and you will need to enable them manually.
Create AD Users in Bulk with PowerShell
In most modern scenarios, the New-ADUser PowerShell cmdlet from the Active Directory for Windows PowerShell module is used to create user accounts in AD in bulk. The main advantage of this method is that you can do almost any additional action after the creation of a user: set unique passwords for users and activate accounts, send email notification of new user creation, add users to AD security groups, create mailboxes, etc.
The idea in this case is similar. First, you need to create a CSV file containing a list of the users and their attributes that need to be created in Active Directory. Then, use a ForEach loop to create an account for each user by using the New-ADUser cmdlet.
You must create an XLSX file with the following columns as a minimum: FirstName,
LastName, sAMAccountName, OU, Password
Export Excel file to CSV format with commas as separators (File > Save as > File type: CSV, File name: new_ad_users.csv).
Open PowerShell ISE or VSCode with the PowerShell module and run the following script to create new users in bulk from your CSV file:
$userList = Import-Csv -Path $csvPath -Delimiter "," foreach ($user in $userList) { $firstName = $user.FirstName $lastName = $user.LastName $sAMAccountName = $user.sAMAccountName $OU=$user.OU $Password = ConvertTo-SecureString $user.Password -AsPlainText -Force if (-not (Get-ADUser -Filter {SamAccountName -eq $sAMAccountName})) { New-ADUser -Name "$firstName $lastName" -GivenName $firstName -Surname $lastName -SamAccountName $sAMAccountName -AccountPassword $Password -Enabled $true -Path $ou Write-Host "User $sAMAccountName created successfully." } else { Write-Host "User $sAMAccountName already exists." } } Write-Host "Bulk user creation completed."
The script took a few seconds to import the data from the file, create new users in AD and set them unique passwords according to your CSV file.
When you create a user, you can immediately fill in other user attributes in AD (email, phone, job title, department, address, etc.). Simply add the appropriate columns to the CSV file and populate the data.
Then modify the script to add other user attributes as options to the New-ADUser command (see the Microsoft documentation for a complete list of the New-ADUser available parameters and cmdlet syntax).