Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Import-Module ActiveDirectory
  2.  
  3. $path = Split-Path -parent $MyInvocation.MyCommand.Definition
  4. $importPath = $path + "users.txt"
  5. # EDIT to fit your domain
  6. $domain = "@yourdomain.local"
  7. # EDIT to fit the ou you want to create your users in - make shure it exists
  8. $location = "OU=SharePoint,OU=Service Users,OU=Users,DC=yourdomain,DC=local"
  9. # EDIT to fit your password policy - otherwise creation will fail
  10. $initialPass = ConvertTo-SecureString -AsPlainText "Pass@Word1" -force
  11.  
  12. Import-CSV $importPath | ForEach-Object {
  13. $sam = $_.Username.ToLower()
  14. Try { $exists = Get-ADUser -LDAPFilter "(sAMAccountName=$sam)" }
  15. Catch { }
  16. If(!$exists)
  17. {
  18. $upn = $sam + $domain
  19. New-ADUser $_.Name -SamAccountName $sam -Path $location -DisplayName $_.Name -UserPrincipalName $upn -AccountPassword $initialPass
  20.  
  21. $user = Get-ADUser -LDAPFilter "(sAMAccountName=$sam)"
  22.  
  23. Enable-ADAccount -Identity $user
  24. Unlock-ADAccount -Identity $user
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement