Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Script:
- # 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)
- $userInstance = Get-ADUser -Identity "_RDSTemplate"
- $users = Import-CSV "c:\scripts\users.csv"
- foreach ($i in $users) {
- $FirstName = $i.FirstName
- $LastName = $i.LastName
- $SamAccountName = $i.SamAccountName
- $DisplayName = $i.Name
- $AccountPassword = $i.AccountPassword
- $UserPrincipalName = $i.UserPrincipalName
- $Path = "ou=NewInterns,ou=Interns,ou=Employees,dc=domain,dc=org"
- $UserProfile = "\\fileshare\profiles\"
- $UserProfile += $i.SamAccountName
- $scriptPath = "login-new.bat"
- $HomeDirectory = "\\fileshare\users\"
- $homeDirectory += $i.SamAccountName
- 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"
- }
- CSV format:
- FirstName,LastName,SamAccountName,Name,AccountPassword,UserPrincipalName
- Joe,User,juser,Joe User,P@ssw0rd,juser@domain.org
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement