This script uses the ‘Active Directory module for Windows Powershell’ but the key point (that took me ages to work out, and seems mad) is you should not run it from a domain controller! instead I ran it from a member server while logged in as a Domain Admin.
The Script
Import-Csv .\2012Users.csv | foreach-object {
$userprinicpalname = $_.SamAccountName + “@yourdomain.com”
New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $_.name -DisplayName $_.name -GivenName $_.FirstName -SurName $_.LastName -Path “OU=year7,OU=Pupils,DC=yourdomain,DC=com” -AccountPassword (ConvertTo-SecureString “Passwordgoeshere” -AsPlainText -force) -Enabled $True -ChangePasswordAtLogon $True -PassThru }
The CSV should have the following columns
FirstName
LastName
name
SamAccountName
When you run the script, it will create the users, using their login name as the Display name.