User Tools

Site Tools


windows:create_ad_user

This is an old revision of the document!


Create AD User

Input CSV file:

cn,givenname,sn,sAMAccountName,displayname,UserPrincipalName
Joe Smith,Joe,Smith,jsmith,Joe Smith,jsmith@domain.com
Susan Johnson,Susan,Johnson,sjohnson,Susan Johnson,sjohnson@domain.com

Code:

$inputFile = Import-CSV  <insert filepath here>
foreach($line in $inputFile)
{
    ## need to add quotes around DSN        
    $dsn = "`"cn="+$line.cn+",ou=userou,dc=domain,dc=com`""
    $samid = $line.sAMAccountName
    $ln = $line.sn
    $fn = $line.givenname
    $dn = $line.displayname
    ## need to add quotes around display name
    $dn2 = "`"$dn`""
    $upn = $line.UserPrincipalName

    cmd /c "dsadd user $dsn -samid $samid -ln $ln -fn $fn -display $dn2
    -upn $upn -mustchpwd yes -pwd TempP@assw0rd"

    write-host `n
}    

Good luck!

Fields

  • SAM NName
  • First Name
  • Last Name
  • Password
  • DN Prefirx (,OU=import,OU=Students,DC=SEBEKASCHOOLS,DC=NET)
  • Group DN ( CN=HighSchoolStudents,OU=Students,DC=SEBEKASCHOOLS,DC=NET)
  • Profile Path ( \\cfs\profile\testuser25)
  • UPN (testuser25@sebekaschools.net)
dsadd user "CN=test user25,OU=import,OU=Students,DC=SEBEKASCHOOLS,DC=NET" -samid testuser25 -ln user -fn test -display "test user" -mustchpwd no -pwd 12345678 -memberof CN=HighSchoolStudents,OU=Students,DC=SEBEKASCHOOLS,DC=NET -profile \\cfs\profile\testuser25 -upn testuser25@sebekaschools.net
windows/create_ad_user.1422559236.txt.gz · Last modified: 2015/01/29 13:20 by tschulz