Skip to content

Instantly share code, notes, and snippets.

@rberrelleza
Last active December 19, 2015 00:39
Show Gist options
  • Save rberrelleza/5870412 to your computer and use it in GitHub Desktop.
Save rberrelleza/5870412 to your computer and use it in GitHub Desktop.
Create AD users from a CSV
$domain = (get-addomain).distinguishedname
$location = "OU=Engineering,$domain"
$domain_email = 'yourdomain.com'
$i = 0
Get-Content .\names.csv.txt | ForEach {
$i++
$names = $_.Split()
$first = $names[0]
$last = $names[1]
$username = "$first" + "." + "$last"
$email = "$username" + $domain_email
$password = ConvertTo-SecureString -AsPlainText "somethingG00D!" -force
$sam = $first + '.' + $last
New-ADUser $sam -AccountPassword $password -EmailAddress $email -UserPrincipalName $email -Enabled $true -GivenName $first -Surname $last
$dn = (Get-ADUser $sam).DistinguishedName
Move-ADObject -Identity $dn -TargetPath $location
$i.ToString() + ") Name: " + $dn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment