One of the biggest challenges for IT administrators to Active Directory bulk user creation. Using the native Active Directory (AD) tools or PowerShell scripts to set each user and configure their properties in AD is a time-consuming task.
We can use PowerShell scripts to create users in bulk from a CSV file and it can save a lot of time compared to manually. Here is a sample CSV file that can be used along with the Powershell script.
Powershell script:
Import-Module ActiveDirectory
ADUsers = Import-CSV c:\ad_data\bulk_users.csv
foreach ($User in $ADUsers)
{
#Read user data from each field in each row and assign the data to a variable as below
$Username = $User.username
$Password = $User.password
$Firstname = $User.firstname
$Lastname = $User.lastname
$OU = $User.ou #This field refers to the OU the user account is to be created in
$email = $User.email
$streetaddress = $User.streetaddress
$city = $User.city
$zipcode = $User.zipcode
$state = $User.state
$country = $User.country
$telephone = $User.telephone
$jobtitle = $User.jobtitle
$company = $User.company
$department = $User.department
$Password = $User.Password
$descriptionn = $user.description
#Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username})
{
#If user does exist, give a warning
Write-Warning "A user account with username $Username already exist in Active Directory."
}
else
{
#User does not exist then proceed to create the new user account
#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADUser `
-SamAccountName $Username `
-UserPrincipalName "$Username@infoalias.local" `
-Name "$Firstname $Lastname" `
-GivenName $Firstname `
-Surname $Lastname `
-Enabled $True `
-DisplayName "$Firstname $Lastname" `
-Path $OU `
-City $city `
-Company $company `
-State $state `
-StreetAddress $streetaddress `
-OfficePhone $telephone `
-EmailAddress $email `
-Title $jobtitle `
-Department $department `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True
}
}
i am try this not working
you can watch the video Bulk user creation video
https://www.youtube.com/watch?v=V0Ygxyl36Mk&t=128s
Very useful video and site. Thank you : )
To get it to work I had to amend Line 2 in above script from:
ADUsers = Import-CSV c:\ad_data\bulk_users.csv
to:
$ADUsers = Import-CSV c:\ad_data\bulk_users.csv