Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. $firstname = get-content C:\Script\firstnames
  2. $lastname = get-content C:\Script\lastnames
  3. $OU = "OU=Gothenburg,OU=Users,OU=LAB,DC=ad,DC=lab,DC=se", "OU=Stockholm,OU=Users,OU=LAB,DC=ad,DC=lab,DC=se", "OU=Malmo,OU=Users,OU=LAB,DC=ad,DC=lab,DC=se"
  4. $suffix = "lab.se"
  5. $department = "Sales", "Marketing", "Production", "Managers"
  6.  
  7. if
  8. (get-adforest | ? UPNsuffixes -eq $suffix) {Write-Host "UPN Suffix $suffix already existing" -ForegroundColor Red}
  9.  
  10. else {
  11. set-adforest -upnsuffixes @{add=$suffix} -Identity LAB
  12. Write-host "Created the suffix $suffix successfully" -ForegroundColor Green
  13. }
  14.  
  15.  
  16. 1..1000 | % {
  17.  
  18. $randomOU = $OU | Get-Random
  19. $Randomfname = $firstname | Get-Random
  20. $Randomlname = $lastname | Get-Random
  21. $Randomfullname = $randomfname+" "+$randomlname
  22. $Randomdepartment = $department | Get-Random
  23. $UPN = $Randomfname.ToLower()+"."+$Randomlname.ToLower()+"@"+$suffix
  24.  
  25. $randomyear = 53..99 | get-random
  26. $samaccountname = $Randomfname.substring(0,3)+$Randomlname.substring(0,3)+$randomyear
  27. $PrimaryProxyaddress = "SMTP:"+$UPN
  28. $SecondaryAddress = "smtp:"+$samaccountname+$suffix
  29.  
  30. $securepassword = ConvertTo-SecureString -string "P@ssw0rd" -AsPlainText -force
  31.  
  32. Write-Host "Creating user $Randomfullname with $UPN" -ForegroundColor Green
  33.  
  34.  
  35. $ADuser = New-ADuser `
  36. -name $Randomfullname `
  37. -AccountPassword $securepassword `
  38. -Enabled:$true `
  39. -path $randomOU `
  40. -UserPrincipalName "$UPN" `
  41. -samaccountname $samaccountname `
  42. -DisplayName $Randomfullname `
  43. -GivenName $Randomfname `
  44. -Surname $Randomlname `
  45. -emailaddress $UPN `
  46. -department $Randomdepartment `
  47. -Passthru
  48.  
  49. Set-ADUser $ADuser -Add @{Proxyaddresses=$PrimaryProxyaddress,$SecondaryAddress}
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement