Advertisement
Guest User

Simple AD User Creation

a guest
Nov 25th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Script:
  2.  
  3. # We're going to copy the _RDSTemplate User as a default group assignment. This is a disabled User Object that has the proper security groups and settings that we want for a default user object (specifically, Interns)
  4. $userInstance = Get-ADUser -Identity "_RDSTemplate"
  5. $users = Import-CSV "c:\scripts\users.csv"
  6. foreach ($i in $users) {
  7.     $FirstName = $i.FirstName
  8.     $LastName = $i.LastName
  9.     $SamAccountName = $i.SamAccountName
  10.     $DisplayName = $i.Name
  11.     $AccountPassword = $i.AccountPassword
  12.     $UserPrincipalName = $i.UserPrincipalName
  13.     $Path = "ou=NewInterns,ou=Interns,ou=Employees,dc=domain,dc=org"
  14.     $UserProfile = "\\fileshare\profiles\"
  15.     $UserProfile += $i.SamAccountName
  16.     $scriptPath = "login-new.bat"
  17.     $HomeDirectory = "\\fileshare\users\"
  18.     $homeDirectory += $i.SamAccountName
  19.     New-ADUser -Name $DisplayName -DisplayName $Displayname -SamAccountName $SamAccountName -AccountPassword (ConvertTo-SecureString $AccountPassword -AsPlainText -Force) -Instance $userInstance -Path "ou=NewInterns,ou=Interns,ou=Employees,dc=domain,dc=org" -UserPrincipalName $UserPrincipalName -GivenName $FirstName -Surname $LastName -PasswordNeverExpires $False -ChangePasswordAtLogon $False -ProfilePath $UserProfile -ScriptPath $scriptPath -Enabled $True -HomeDrive "U:" -HomeDirectory $HomeDirectory | Tee-Object "C:\TEMP\user_create_log.txt"
  20. }
  21.  
  22. CSV format:
  23. FirstName,LastName,SamAccountName,Name,AccountPassword,UserPrincipalName
  24. Joe,User,juser,Joe User,P@ssw0rd,juser@domain.org
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement