Useful PowerShell Script to Bulk Create Users
Aug 26, 2013 14:04 · 106 words · 1 minute read
Just used this script to generate 4000 users accounts within a development Active Directory.
The CSV has to be in the format:
##### CSV FILE ########
Name,Firstname,Password
User1,test,P@$$w0rd!1
User2,test,P@$$w0rd!1
User3,test,P@$$w0rd!1
User4,test,P@$$w0rd!1
############### START SCRIPT ################
Import-Module ActiveDirectory
$Users = Import-Csv -Delimiter “;” -Path “.\users.csv”
foreach ($User in $Users)
{
$OU = “OU=Employees,DC=lab-os,DC=com”
$Password = $User.password
$Detailedname = $User.firstname + " " + $User.name
$UserFirstname = $User.Firstname
$FirstLetterFirstname = $UserFirstname.substring(0,1)
$SAM = $FirstLetterFirstname + $User.name
New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -GivenName $user.firstname -Surname $user.name -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path $OU
}
############### END SCRIPT ################
Script credit goes to http://gallery.technet.microsoft.com/scriptcenter/ed20b349-9758-4c70-adc0-19c5acfcae45