Advertisement
Guest User

Untitled

a guest
Sep 7th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #Import AD Silently
  2. Import-Module ActiveDirectory -ErrorAction SilentlyContinue
  3.  
  4. #Grab dynamic Variables
  5. $givenname = Read-Host "Input given name"
  6. $surname = Read-Host "Input surname"
  7. $jobtitle = Read-Host "Input job title"
  8. $department = Read-Host "Input Department"
  9. $password = Read-Host -AsSecureString "Password"
  10. $Office = Read-Host "Input Office"
  11. $Manager = Read-Host "Manager"
  12.  
  13. #set static variables
  14. $homepath = "\\shipleyfs2\users\"
  15. $domain = '@' + (Get-ADDomain).dnsroot
  16. $lowerLN = $surname.Tolower()
  17. $lowerFN = $givenname.Tolower()
  18. $logon = "$lowerFN.$lowerLN"
  19. $email = "@accentgroup.org"
  20.  
  21. #Set the Address Tab Info variables
  22. if ($office -like 'Charlestown House') {
  23. $Street = "Acorn Park Industrial Estate"
  24. $City = "Charlestown"
  25. $state = "Shipley"
  26. $Zip = "BD17 7SW"
  27. }
  28.  
  29. #Set new variables
  30. $Attributes =@{
  31.  
  32. Enabled = $True
  33. Name = "$givenname $surname"
  34. Givenname = $givenname
  35. Surname = $surname
  36. SamAccountName = $logon
  37. UserPrincipalName = "$logon$domain"
  38. DisplayName = "$givenname $surname"
  39. Department = "$Department"
  40. Description = $jobtitle
  41. EmailAddress = "$lowerFN.$lowerLN$email"
  42. Title = $jobtitle
  43. Office = $Office
  44. Company = "Accent Corporate Services Limited"
  45. AccountPassword = $password
  46. HomeDrive = "H:"
  47. HomeDirectory = "$homepath$logon"
  48. StreetAddress = $Street
  49. City = $City
  50. State = $state
  51. PostalCode = $zip
  52. Country = "GB"
  53. Manager = get-aduser -Filter 'Name -like "$Manager"' -Properties SamAccountName | Select-Object -ExpandProperty SamAccountName
  54.  
  55.  
  56. }
  57.  
  58. ##Creating our new Domain User
  59. $mkuser = new-aduser $Attributes
  60.  
  61. #Make sure that the account has to change it's password after the first logon
  62. $ChgPass = set-aduser -identity $logon -ChangePasswordAtLogon $True
  63.  
  64. #This is where my adding to groups would go.....IF I HAD THEM!
  65.  
  66. #Check to see if account exists
  67. #$complete = get-aduser -identity $logon
  68.  
  69. #Look for the account in question, and if missing create it.
  70. If (!(Get-ADUser -Identity $logon))
  71. {
  72. & $mkuser
  73. & $ChgPass
  74. }
  75. else
  76. {
  77. Write-Host "The username already exists."
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement