Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###########################################
- #
- # adds users to AD from CSV file using the
- # semicolon as a delimiter
- #
- # the variables $myOU, $myDC1 and $myDC2
- # are for the LDAP path, feel free to
- # modify these
- #
- ###########################################
- ### DECLARING VARIABLES ###
- $myOU = "villach"
- $myDC1 = "kurs"
- $myDC2 = "local"
- #LDAP path to the OU where i want the new users
- $objOU = [ADSI]"LDAP://OU=$myOU,DC=$myDC1,DC=$myDC2"
- #path to the csv file
- $csvurl = "C:\test\importme.csv"
- #throwing the csv into a var
- $users = Import-Csv $csvurl -delimiter ";"
- ### THE ACTUAL SCRIPT ###
- #for each line in the csv do {}
- $users | foreach {
- #merging the first and last name to make a username
- $Username = $_.firstname + $_.lastname
- #creating the new $_.class(user or computer or w/e) object in this OU
- $newuser = $objOU.Create($_.class, "cn=" + $_.commonname)
- #giving the new user a sAMAccountName
- $newuser.put("sAMAccountName", $_.commonname)
- #writing the info to the AD
- $newuser.setinfo()
- #enabling account
- $newuser.psbase.invokeset('accountdisabled', $false)
- $newuser.setinfo()
- #setting a password
- $newuser.setpassword("wifi1234!")
- $newuser.setinfo()
- #confirm the creation to the user
- Write-Host created $username
- }
- ###########################################
- #
- # used CSV file:
- #
- # class;commonname;password;firstname;lastname
- # user;m.mouse;wifi1234!;mickey;mouse
- # user;d.duck;wifi1234!;donald;duck
- # user;g.goof;herpderp;goofy;goof
- # user;h.duck;donaldsucks;hewey;duck
- # user;f.duck;givecandy;fred;duck
- #
- ###########################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement