Advertisement
Guest User

basic script

a guest
Aug 25th, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #Set Variables
  2. $FIRSTNAME = Read-Host "What is the users first name?"
  3. $LASTNAME = Read-Host "What is the users last name?"
  4. $USERNAME = Read-Host "What is the username of the user?"
  5. $DOMAINNAME = Read-Host "What is the domain name?"
  6. $USERPASS = Read-Host "What is the account password?"
  7. $CHANGEPASS = Read-Host "Does user need to change password on first logon? Y or N"
  8. $USERPATH = Read-Host "Distinguished name path"
  9.  
  10. #Convert Password to secure
  11. $SECUREPASS = (ConvertTo-SecureString "$USERPASS" -AsPlainText -Force)
  12.  
  13. #Set Password Policy
  14. IF ($CHANGEPASS -eq "Y"){$PASSPOLICY=$true}
  15. IF ($CHANGEPASS -eq "N"){$PASSPOLICY=$false}
  16.  
  17. #Commands
  18. New-ADUser `
  19. -Name "$FIRSTNAME $LASTNAME" `
  20. -GivenName $FIRSTNAME `
  21. -Surname $LASTNAME `
  22. -SamAccountName $USERNAME `
  23. -UserPrincipalName "$USERNAME@$DOMAINNAME" `
  24. -AccountPassword $SECUREPASS -PassThru `
  25. -ChangePasswordAtLogon $PASSPOLICY `
  26. -Path $USERPATH
  27.  
  28. #Ask if in group
  29. $GROUPMEMEBER = Read-Host "Is user a member of a group? Y or N"
  30. IF ($GROUPMEMEBER -eq "Y"){
  31. #Add user to group
  32. $GROUP = Read-Host "What group is user a member of?"
  33. Add-ADGroupMember -Identity "$GROUP" -Members "$USERNAME"
  34. }
  35. IF ($GROUPMEMEBER -eq "N"){$RERUN}
  36.  
  37. #Rerun Command
  38. $RERUN = Read-Host "Run the script again? Press Y or N"
  39. IF ($RERUN -eq "Y"){&.\add_user_with_pass.ps1}
  40. IF ($RERUN -eq "N"){exit}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement