Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Set script Parameters for the inputs
- param (
- [String]$First,
- [String]$Last,
- [String]$SamAccountName
- )
- #Set Message Strings for the Function Message-Prompt
- $MsgGADSSync = "Do you want to run a test GADS Sync?"
- $MsgGADSResultApply = "Were the sync results correct? and should we apply the sync?"
- $MsgCreateUser = "Do you want to create this user?"
- $SchoolPrompt = "Is This a High School Student [1] or an Elementary Student [2]"
- #Create Functions
- #the message prompting function and return a value 0 or 1 (false or true repsectively)
- function Message-Prompt
- {
- param (
- [String]$MessageX
- )
- Do{
- Write-Host "$messagex" -ForegroundColor Yellow
- Write-Host "[Y] Yes or [N] No" -ForegroundColor Cyan
- $choicex = Read-Host -Prompt "Select an option"
- } until ($choicex -eq "y" -or $choicex -eq "n" -or $choicex -eq "yes" -or $choicex -eq "no")
- If ($choicex -eq "y" -or $choicex -eq "yes"){
- Set-Variable -Name ReturnValue -Value "1" -Scope Script
- }
- elseif ($choicex -eq "n" -or $choicex -eq "no"){
- Set-Variable -Name ReturnValue -Value "0" -Scope Script
- }
- else {
- exit
- }
- }
- # Function reset return value
- function Reset-ReturnValue
- {
- Set-Variable -Name ReturnValue -Value 99 -Scope Script
- }
- #Prompts for more data
- $School = "Default Value Please Change"
- Do{
- Write-Host "$SchoolPrompt" -ForegroundColor Yellow
- Write-Host "[1] High School or [2] Elementary" -ForegroundColor Cyan
- $SchoolSelected = Read-Host -Prompt "Select an option"
- } until ($SchoolSelected -eq "1" -or $SchoolSelected -eq "2")
- If ($SchoolSelected -eq "1") {
- Set-Variable -Name School -Value "hs_students" -Scope script
- }
- else {
- Set-Variable -Name School -Value "el_students" -Scope script
- }
- #More prompts and more data
- $Path = Read-Host "Enter GraduationYear"
- $Password = Read-Host "Set User Password"
- #build other information using what has already been prompted for
- $Fullname = "$($First) $($Last)"
- $UserPrincipleName = "$($SamAccountName)@mr1.local"
- $EmailAddress = "$($SamAccountName)@maysville.k12.mo.us"
- $FullPath = "OU=$($Path),OU=$($school),OU=Student_Accounts,OU=User Accounts,DC=mr1,DC=local"
- #Print out what will be created
- Write-Host "Does the Data Look Correct?" -ForegroundColor Magenta
- Write-Host "$FullName" -ForegroundColor Yellow
- Write-host "$SamAccountName" -ForegroundColor Yellow
- Write-host "$EmailAddress" -ForegroundColor Yellow
- Write-host "$FullPath" -ForegroundColor Yellow
- Write-Host "`n"
- #prompt for account creation and run the results
- Message-Prompt $MsgCreateUser
- If ($ReturnValue -eq "1") {
- New-ADUser -GivenName $First -Surname $Last -Name $Fullname -DisplayName $FullName -SamAccountName $SamAccountName -UserPrincipalName $UserPrincipleName -EmailAddress $EmailAddress -Path $FullPath -Enabled $True #-AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -ChangePasswordAtLogon $True
- Add-ADGroupMember $Path $SamAccountName
- }
- else {
- Exit
- }
- #Prompt and ask for the GADS portion of the script.
- Message-Prompt $MsgGADSSync
- If ($ReturnValue -eq "1") {
- Invoke-Command -ComputerName utilityserver -ScriptBlock {& 'c:\Program Files\Google Apps Directory Sync\sync-cmd.exe'"-c c:\gads\configurations\current_final_v1"}
- }
- else{
- Write-Host "Continuing On.."
- }
- #Clear Return Value
- Reset-ReturnValue
- #Prompt Apply GADS Sync
- Message-Prompt $MsgGADSResultApply
- If ($ReturnValue -eq "1") {
- Write-host "Applying Google Apps Sync In 3 seconds. Ctrl+c to quit"
- Start-Sleep -s 3
- Invoke-Command -ComputerName utilityserver -ScriptBlock {& 'c:\Program Files\Google Apps Directory Sync\sync-cmd.exe'"-c c:\gads\configurations\current_final_v1" "-a"}
- }
- else {
- Write-Host "Continuing on..."
- }
- Reset-ReturnValue
- #Set the password parameters based on $school variable
- Write-Host "Setting Password Parameters Based On $School Value"
- If ($School -eq "hs_students") {
- Set-AdAccountPassword -identity $SamAccountName -reset -newpassword (ConvertTo-SecureString $Password -AsPlainText -force) -Verbose | Set-ADUser -ChangePasswordAtLogon $True -Verbose
- }
- Else {
- Set-AdAccountPassword -identity $SamAccountName -reset -newpassword (ConvertTo-SecureString $Password -AsPlainText -force) -Verbose | Set-Aduser -CannotChangePassword $True -ChangePasswordAtLogon $False -PasswordNeverExpires $True -Verbose
- }
- Write-Host "ALL DONE!!!" -ForegroundColor Magenta
- Start-Sleep -s 1
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement