Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Set Variables
- $FIRSTNAME = Read-Host "What is the users first name?"
- $LASTNAME = Read-Host "What is the users last name?"
- $USERNAME = Read-Host "What is the username of the user?"
- $DOMAINNAME = Read-Host "What is the domain name?"
- $USERPASS = Read-Host "What is the account password?"
- $CHANGEPASS = Read-Host "Does user need to change password on first logon? Y or N"
- $USERPATH = Read-Host "Distinguished name path"
- #Convert Password to secure
- $SECUREPASS = (ConvertTo-SecureString "$USERPASS" -AsPlainText -Force)
- #Set Password Policy
- IF ($CHANGEPASS -eq "Y"){$PASSPOLICY=$true}
- IF ($CHANGEPASS -eq "N"){$PASSPOLICY=$false}
- #Commands
- New-ADUser `
- -Name "$FIRSTNAME $LASTNAME" `
- -GivenName $FIRSTNAME `
- -Surname $LASTNAME `
- -SamAccountName $USERNAME `
- -UserPrincipalName "$USERNAME@$DOMAINNAME" `
- -AccountPassword $SECUREPASS -PassThru `
- -ChangePasswordAtLogon $PASSPOLICY `
- -Path $USERPATH
- #Ask if in group
- $GROUPMEMEBER = Read-Host "Is user a member of a group? Y or N"
- IF ($GROUPMEMEBER -eq "Y"){
- #Add user to group
- $GROUP = Read-Host "What group is user a member of?"
- Add-ADGroupMember -Identity "$GROUP" -Members "$USERNAME"
- }
- IF ($GROUPMEMEBER -eq "N"){$RERUN}
- #Rerun Command
- $RERUN = Read-Host "Run the script again? Press Y or N"
- IF ($RERUN -eq "Y"){&.\add_user_with_pass.ps1}
- IF ($RERUN -eq "N"){exit}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement