Creating bulk user accounts in Active Directory

Sharing is caring!

This is very common requirement when creating new users. Its much easier to create bulk user using csv file or excel file rather than creating each user manually.
There are lot of tools available some are free some you have to pay for to achieve that. We have created following script to fulfil our requirements. Please use one which is required according your environment and change where its necessary.
Solution One:
Below is powershell script, which will create users in Active directory, please run this powershell script in “Active Directory Module For Windows PowerShell”.

Create “users.csv” file

Import-Csv .users.csv | foreach-object {
$userprinicpalname = $_.SamAccountName + “@{domainname}.com”
New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $_.name -DisplayName $_.name -GivenName $_.cn -SurName $_.sn -Department $_.Department -Path “CN=Users,DC=biogen,DC=com” -AccountPassword (ConvertTo-SecureString “Power~1;” -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True –PassThru}
Solution Two:
Create Excel sheet called “Users.xls”
Set objExcel = CreateObject(“Excel.Application”) Set objWorkbook = objExcel.Workbooks.Open _(“C:Scriptsusers.xls”) intRow = 2

Do Until objExcel.Cells(intRow,1).Value = “”   

Set objOU = GetObject(“ou=Finance, dc=fabrikam, dc=com”)

Set objUser = objOU.Create _

(“User”, “cn=” & objExcel.Cells(intRow, 1).Value)    

objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value     objUser.GivenName = objExcel.Cells(intRow, 3).Value    

objUser.SN = objExcel.Cells(intRow, 4).Value    

objUser.AccountDisabled = FALSE 

objUser.SetInfo

intRow = intRow + 1

Loop

objExcel.Quit 

* Credit to Microsoft MSDN

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.