Advertisement
SignalWarrant

Create New Active Directory Users in Bulk with Password veri

Jun 22nd, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #  *** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK ***
  2. <#
  3.  
  4. .DESCRIPTION
  5.     Creates Active Directory Users in Bulk using a CSV file. Requires a typed password
  6.     and a confirmation that matches to execute.
  7.  
  8. .NOTES
  9.     File Name: New-ADUser.ps1
  10.     Author: David Hall
  11.     Contact Info:
  12.         Website: www.signalwarrant.com
  13.         Twitter: @signalwarrant
  14.         Facebook: facebook.com/signalwarrant/
  15.         Google +: plus.google.com/113307879414407675617
  16.         YouTube Subscribe link: https://www.youtube.com/c/SignalWarrant1?sub_confirmation=1
  17.     Requires: Appropriate AD permissions
  18.     Tested: PowerShell Version 5, Windows 10 and Windows Server 2012 R2
  19.  
  20. .PARAMETER
  21.     None
  22.          
  23. .EXAMPLE
  24.     Run it from the ISE or console
  25.  
  26. #>
  27.  
  28. ###############################################################
  29. #
  30. # Confirm-Password function
  31. #
  32. ###############################################################
  33. Function confirm-Password{
  34.     $match = $false
  35.     while($match -eq $false) {
  36.         $PWD1 = Read-Host "ENTER PASSWORD"
  37.         $PWD2 = Read-Host "CONFIRM PASSWORD"
  38.  
  39.         if($PWD1 -ne $PWD2) {
  40.             Write-Warning "Passwords Do Not Match - Please Try Again ..."
  41.             break
  42.          }
  43.          
  44.          if($PWD1 -eq "" -or $PWD2 -eq "")  {
  45.             Write-Warning "Password Cannot be BLANK - Please Try Again ..."
  46.             break
  47.         }
  48.             return $PWD1
  49.         }
  50.     }
  51. ###############################################################
  52. #
  53. # End Confirm-Password function
  54. #
  55. ###############################################################
  56.  
  57. $import = 'c:\scripts\users.csv'
  58. $password = confirm-password
  59.  
  60. if($password -ne "") {
  61.     Import-CSV $import | ForEach {
  62.         $user = New-ADUser `
  63.             -SamAccountName ($_.FName+"."+$_.Lname) `
  64.             -Name ($_.FName+" "+$_.LName) `
  65.             -Displayname ($_.FName+" "+$_.LName) `
  66.             -UserPrincipalName ($_.UserPrincipalName) `
  67.             -Surname ($_.LName) `
  68.             -GivenName ($_.Fname)  `
  69.             -Path ($_.ou) `
  70.             -AccountPassword (ConvertTo-SecureString -AsPlainText $password -force )`
  71.             -Enabled $true `
  72.             -PasswordNeverExpires $false `
  73.             -ChangePasswordAtLogon $true `
  74.             -PassThru
  75.         }
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement