Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #Enter a path to your import CSV file
  2. $ADUsers = Import-csv C:\scripts\newusers.csv
  3.  
  4. foreach ($User in $ADUsers)
  5. {
  6.  
  7. $Username = $User.username
  8. $Password = $User.password
  9. $Firstname = $User.firstname
  10. $Lastname = $User.lastname
  11. $Department = $User.department
  12. $OU = $User.ou
  13. $function = $User.function
  14. $location = $User.location
  15. $telephone = $User.telephone
  16.  
  17. #Check if the user account already exists in AD
  18. if (Get-ADUser -F {SamAccountName -eq $Username})
  19. {
  20. #If user does exist, output a warning message
  21. Write-Warning "A user account $Username has already exist in Active Directory."
  22. }
  23. else
  24. {
  25. #If a user does not exist then create a new user account
  26.  
  27. #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
  28. New-ADUser `
  29. -SamAccountName $Username `
  30. -UserPrincipalName "$Username@fitnu.local" `
  31. -Name "$Firstname $Lastname" `
  32. -GivenName $Firstname `
  33. -Surname $Lastname `
  34. -Enabled $True `
  35. -ChangePasswordAtLogon $True `
  36. -DisplayName "$Lastname, $Firstname" `
  37. -MobilePhone $telephone `
  38. -Title $function `
  39. -City $location `
  40. -Department $Department `
  41. -Path $OU `
  42. -AccountPassword (convertto-securestring $Password -AsPlainText -Force)
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement