Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
4,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. $Username = $User.username
  2. $Password = $User.password
  3. $Firstname = $User.firstname
  4. $Lastname = $User.lastname
  5. $OU = $User.ou #This field refers to the OU the user account is to be created in
  6. $email = $User.email
  7. $Password = $User.Password
  8. $groups = $User.groups
  9.  
  10. #Check to see if the user already exists in AD
  11. if (Get-ADUser -F {SamAccountName -eq $Username})
  12. {
  13. #If user does exist, give a warning
  14. Write-Warning "A user account with username $Username already exist in Active Directory."
  15. }
  16. else
  17. {
  18. #User does not exist then proceed to create the new user account
  19.  
  20. #Account will be created in the OU provided by the $OU variable read from the CSV file
  21. New-ADUser `
  22. -SamAccountName $username `
  23. -UserPrincipalName "$username@lon.deloitterisk.cloud" `
  24. -Name "$Firstname $Lastname" `
  25. -GivenName $Firstname `
  26. -Surname $Lastname `
  27. -Enabled $True `
  28. -DisplayName "$Lastname, $Firstname" `
  29. -Path $OU `
  30. -AccountPassword (convertto-securestring $Password -AsPlainText -
  31. Force) -ChangePasswordAtLogon $False -PasswordNeverExpires:$True `
  32. -group
  33. {
  34. foreach($groups in $ADUsers)
  35.  
  36. {
  37. $Username = $User.username
  38. $groups = $User.groups -split ","
  39.  
  40. foreach ($group in $groups)
  41. }
  42. }
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement