Advertisement
Guest User

Untitled

a guest
Nov 9th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #Enter a path to your import CSV file
  2. $ADUsers = Import-csv C:\Users\Administrator\scripts\users.csv
  3. foreach ($User in $ADUsers)
  4. {
  5. $Username = $User.username
  6. $Password = $User.password
  7. $Firstname = $User.firstname
  8. $Lastname = $User.lastname
  9. $OU = $User.ou
  10. #Check if the user account already exists in AD
  11. if (Get-ADUser -F {SamAccountName -eq $Username})
  12. {
  13. #If user does exist, output a warning message
  14. Write-Warning "A user account $Username has already exist in Active Directory."
  15. }
  16. else
  17. {
  18. #If a user does not exist then create a new user account
  19. #Account will be created in the OU listed in the $OU variable in the CSV file; don’t forget to change the domain name in the"-UserPrincipalName" variable
  20. New-ADUser `
  21. -SamAccountName $Username `
  22. -UserPrincipalName "$Username@ECORP.local" `
  23. -Name "$Firstname $Lastname" `
  24. -GivenName $Firstname `
  25. -Surname $Lastname `
  26. -Enabled $True `
  27. -ChangePasswordAtLogon $True `
  28. -DisplayName "$Lastname, $Firstname" `
  29. -AccountPassword (convertto-securestring $Password -AsPlainText -Force)
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement