daily pastebin goal
51%
SHARE
TWEET

Random ad user generator

a guest May 17th, 2016 1,026 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. #
  3. #preset variables for the script:
  4. #
  5.  
  6. $date = Get-date -format M.d.yyyy
  7. $ou="OU=LANDING,DC=DEFAULTDOMAIN,DC=COM"
  8. $principlename = "@DEFAULT.com"
  9. $description = "Test Account Generate $date"
  10. $Number_of_users = "5000"
  11. $company = "Test Company"
  12. #Supported Nationalities: AU, BR, CA, CH, DE, DK, ES, FI, FR, GB, IE, IR, NL, NZ, TR, US
  13. #Comma seperated values for multiple ie:
  14. #$nationalities ="US,DK,FR"
  15. $nationalities ="US"
  16.  
  17. #
  18. #end of preset variables for script:
  19. #
  20.  
  21.  
  22. function find_ad_id($first,$last) {
  23.     $first = $first -Replace "\s*"
  24.     $last = $last -Replace "\s*"
  25.     $not_found = $true
  26.     for($i = 1; $i -le $first.length; $i++) {
  27.     $Sam_account =""
  28.     $letters_first = ""
  29.    
  30.         for($l = 0; $l -ne $i; $l++){
  31.         $letters_first += $first[$l]
  32.         }
  33.  
  34.         $sam_account = $letters_first+$last
  35.         if(-not (Get-aduser -Filter {SamaccountName -eq $sam_account})) {
  36.         $not_found = $false
  37.         return $sam_account
  38.         }
  39.     }
  40.    
  41.     if($not_found -eq $true) {
  42.     return "ERROR:FAIL"
  43.     }
  44. }
  45.  
  46.  
  47.  
  48. function generate() {
  49.     $character = @("!","$","%","^","&","*","(",")","?")
  50.     $letters_low=@("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
  51.     $letters_cap=@("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
  52.     $numbers=@("1","2","3","4","5","6","7","8","9","0")
  53.     $itterations = get-random -minimum 8 -maximum 10
  54.     [string]$pass_value = ""
  55.  
  56.     for($i = 0; $i -ne $itterations+1;$i++) {
  57.     $character_type = Get-random -minimum 1 -maximum 9
  58.  
  59.     switch ($character_type) {
  60.         1 { $letter = Get-random -minimum 0 -maximum 26
  61.         $pass_value = $pass_value+$character[$letter]
  62.         }
  63.    
  64.         2 { $letter = Get-random -minimum 0 -maximum 26
  65.         $pass_value = $pass_value+$letters_low[$letter] }
  66.    
  67.         3 { $letter = Get-random -minimum 0 -maximum 11
  68.         $pass_value = $pass_value+$letters_low[$letter] }
  69.  
  70.         4 { $letter = Get-random -minimum 0 -maximum 11
  71.         $pass_value = $pass_value+$letters_cap[$letter] }
  72.  
  73.         5 { $letter = Get-random -minimum 0 -maximum 11
  74.         $pass_value = $pass_value+$character[$letter] }
  75.  
  76.         6 { $letter = Get-random -minimum 0 -maximum 11
  77.         $pass_value = $pass_value+$numbers[$letter] }
  78.    
  79.         7 { $letter = Get-random -minimum 0 -maximum 11
  80.         $pass_value = $pass_value+$letters_cap[$letter] }
  81.        
  82.         8 { $letter = Get-random -minimum 0 -maximum 11
  83.         $pass_value = $pass_value+$letters_cap[$letter]}
  84.     }
  85.  
  86.     $letter = Get-random -minimum 0 -maximum 26
  87.     $pass_value = $pass_value+$character[$letter]
  88.  
  89.     $letter = Get-random -minimum 0 -maximum 11
  90.     $pass_value = $pass_value+$letters_cap[$letter]
  91.  
  92.     $letter = Get-random -minimum 0 -maximum 11
  93.     $pass_value = $pass_value+$numbers[$letter]
  94.     }
  95. return $pass_value
  96. }
  97.  
  98.  
  99.  
  100.  
  101. echo "Status,Date,SamAccountName,Password,FirstName,LastName,DisplayName,City,Phone" >> create_output.csv
  102. $user_data_json_list = invoke-restmethod "https://www.randomuser.me/api/?results=$Number_of_users&nat=$nationalities" | select -expandproperty results
  103. foreach($user_data_json in $user_data_json_list) {
  104.  
  105. $aduser_Given = $user_data_json.name.first
  106. $aduser_Surname = $user_data_json.name.last
  107. $aduser_password = generate
  108. $aduser_display = $user_data_json.name.last + ", " + $user_data_json.name.first
  109. $aduser_phone = $user_data_json.phone
  110. $aduser_city = $user_data_json.location.city
  111. $aduser_samaccountname = find_ad_id $aduser_Given $aduser_Surname
  112.    
  113.     if($aduser_samaccountname -eq "ERROR:FAIL") {
  114.         echo "Failure $aduser_Surname sam account in use"
  115.         echo "Error Samaccount,""$date"",""$aduser_samaccountname"",""$aduser_password"",""$aduser_Given"",""$aduser_Surname"",""$aduser_display"",""$aduser_city"",""$aduser_phone""" >> create_output.csv
  116.     } else {
  117.         New-ADUser -AccountPassword (ConvertTo-SecureString “$aduser_password” -AsPlainText -Force) -ChangePasswordAtLogon $false -City $aduser_city -company “$company_name” -DisplayName “$aduser_display” -Enabled $true -MobilePhone “$aduser_phone” -Name “$aduser_display” -SamAccountName $aduser_samaccountname -Path “$ou" -givenname $aduser_Given -surname $aduser_Surname -userprincipalname (“$aduser_samaccountname” + “$principlename”) -description “$description”
  118.         clear
  119.         Write-Host "`r Generating user: $aduser_Given $aduser_Surname" -NoNewLine
  120.         echo "Success,""$date"",""$aduser_samaccountname"",""$aduser_password"",""$aduser_Given"",""$aduser_Surname"",""$aduser_display"",""$aduser_city"",""$aduser_phone""" >> create_output.csv
  121.     }
  122. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top